Unpack 2d list of tuplesHow do I check if a list is empty?Hidden features of PythonFinding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?Convert bytes to a string?What's the difference between lists and tuples?How to make a flat list out of list of listsHow to clone or copy a list?How to sort (list/tuple) of lists/tuples by the element at a given index?How do I list all files of a directory?

How do I check that users don't write down their passwords?

What is it called when the tritone is added to a minor scale?

Do intermediate subdomains need to exist?

Is there a standard definition of the "stall" phenomena?

Why do Klingons use cloaking devices?

Should I cheat if the majority does it?

Way to see all encrypted fields in Salesforce?

Check whether quotient ring is a field or an integral domain

Convert integer to full text string duration

Stay in US on J-1 visa after quitting job?

What is exact meaning of “ich wäre gern”?

Should I increase my 401(k) contributions, or increase my mortgage payments

Is it possible to spoof an IP address to an exact number?

Convert Front Door Entry Mailbox to a Front & Rear Door Entry Mailbox

Sleepy tired vs physically tired

Why do we need a bootloader separate from our application program in microcontrollers?

Taking my Ph.D. advisor out for dinner after graduation

What is the highest level of accuracy in motion control a Victorian society could achieve?

Is conquering your neighbors to fight a greater enemy a valid strategy?

Can you take the Dodge action while prone?

How frequently do Russian people still refer to others by their patronymic (отчество)?

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Do Goblin tokens count as Goblins?

Does 5e have an equivalent of the Psychic Paper from Doctor Who?



Unpack 2d list of tuples


How do I check if a list is empty?Hidden features of PythonFinding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?Convert bytes to a string?What's the difference between lists and tuples?How to make a flat list out of list of listsHow to clone or copy a list?How to sort (list/tuple) of lists/tuples by the element at a given index?How do I list all files of a directory?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am trying to unpack a 2D list of tuples. Everything I have tried so far is not giving me the results



This is what I am trying to achieve:



Input: [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]] 

Output = [[-8, 2], [0, -1]], [[-8, 0], [2, -1]]


I have tried zip like this but it does not work.



a,b = zip(*matrixRow)









share|improve this question






























    1















    I am trying to unpack a 2D list of tuples. Everything I have tried so far is not giving me the results



    This is what I am trying to achieve:



    Input: [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]] 

    Output = [[-8, 2], [0, -1]], [[-8, 0], [2, -1]]


    I have tried zip like this but it does not work.



    a,b = zip(*matrixRow)









    share|improve this question


























      1












      1








      1








      I am trying to unpack a 2D list of tuples. Everything I have tried so far is not giving me the results



      This is what I am trying to achieve:



      Input: [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]] 

      Output = [[-8, 2], [0, -1]], [[-8, 0], [2, -1]]


      I have tried zip like this but it does not work.



      a,b = zip(*matrixRow)









      share|improve this question
















      I am trying to unpack a 2D list of tuples. Everything I have tried so far is not giving me the results



      This is what I am trying to achieve:



      Input: [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]] 

      Output = [[-8, 2], [0, -1]], [[-8, 0], [2, -1]]


      I have tried zip like this but it does not work.



      a,b = zip(*matrixRow)






      python list tuples






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 20:03









      Pavan Chandaka

      5,7323 gold badges11 silver badges20 bronze badges




      5,7323 gold badges11 silver badges20 bronze badges










      asked Mar 25 at 20:01









      Firzok NadeemFirzok Nadeem

      83 bronze badges




      83 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          you need to apply zip twice to perform 2 transpositions:



          inlist = [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]]

          print(list(zip(*(zip(*x) for x in inlist))))


          result:



          [((-8, 2), (0, -1)), ((-8, 0), (2, -1))]


          this gives tuples inside because zip creates them. To get lists, it's a little more complicated because you have to convert to list at 2 levels:



          print([[list(z) for z in y] for y in zip(*(zip(*x) for x in inlist))])


          prints:



          [[[-8, 2], [0, -1]], [[-8, 0], [2, -1]]]





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345558%2funpack-2d-list-of-tuples%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            you need to apply zip twice to perform 2 transpositions:



            inlist = [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]]

            print(list(zip(*(zip(*x) for x in inlist))))


            result:



            [((-8, 2), (0, -1)), ((-8, 0), (2, -1))]


            this gives tuples inside because zip creates them. To get lists, it's a little more complicated because you have to convert to list at 2 levels:



            print([[list(z) for z in y] for y in zip(*(zip(*x) for x in inlist))])


            prints:



            [[[-8, 2], [0, -1]], [[-8, 0], [2, -1]]]





            share|improve this answer





























              1














              you need to apply zip twice to perform 2 transpositions:



              inlist = [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]]

              print(list(zip(*(zip(*x) for x in inlist))))


              result:



              [((-8, 2), (0, -1)), ((-8, 0), (2, -1))]


              this gives tuples inside because zip creates them. To get lists, it's a little more complicated because you have to convert to list at 2 levels:



              print([[list(z) for z in y] for y in zip(*(zip(*x) for x in inlist))])


              prints:



              [[[-8, 2], [0, -1]], [[-8, 0], [2, -1]]]





              share|improve this answer



























                1












                1








                1







                you need to apply zip twice to perform 2 transpositions:



                inlist = [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]]

                print(list(zip(*(zip(*x) for x in inlist))))


                result:



                [((-8, 2), (0, -1)), ((-8, 0), (2, -1))]


                this gives tuples inside because zip creates them. To get lists, it's a little more complicated because you have to convert to list at 2 levels:



                print([[list(z) for z in y] for y in zip(*(zip(*x) for x in inlist))])


                prints:



                [[[-8, 2], [0, -1]], [[-8, 0], [2, -1]]]





                share|improve this answer















                you need to apply zip twice to perform 2 transpositions:



                inlist = [[(-8, -8), (2, 0)], [(0, 2), (-1, -1)]]

                print(list(zip(*(zip(*x) for x in inlist))))


                result:



                [((-8, 2), (0, -1)), ((-8, 0), (2, -1))]


                this gives tuples inside because zip creates them. To get lists, it's a little more complicated because you have to convert to list at 2 levels:



                print([[list(z) for z in y] for y in zip(*(zip(*x) for x in inlist))])


                prints:



                [[[-8, 2], [0, -1]], [[-8, 0], [2, -1]]]






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 20:16

























                answered Mar 25 at 20:08









                Jean-François FabreJean-François Fabre

                109k10 gold badges68 silver badges123 bronze badges




                109k10 gold badges68 silver badges123 bronze badges


















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345558%2funpack-2d-list-of-tuples%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현