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 Fabre♦Jean-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

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh