Extended zip() for lists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Florian Reiser

    #1

    Extended zip() for lists

    Hello,

    I have 4 lists: a, b, c and d
    Out of this 4 lists I want to build a table (e.g. list of lists):

    a|b|c|d
    ---------------------------
    a1|b1|c1|d1
    a1|b2| |d2

    You see: the lists are not equally sized.
    Is there a command which fills up the shorter lists with blanks?
    Like an enhanced zip() command, maybe?

    Regards
    Florian Reiser

    --
    http://www.ra-bc.de
    RA Unternehmensber atung
    Führen durch präzise Daten


  • gene tani

    #2
    Re: Extended zip() for lists


    Florian Reiser wrote:[color=blue]
    > Hello,
    >
    > I have 4 lists: a, b, c and d
    > Out of this 4 lists I want to build a table (e.g. list of lists):
    >
    > a|b|c|d
    > ---------------------------
    > a1|b1|c1|d1
    > a1|b2| |d2
    >
    > You see: the lists are not equally sized.
    > Is there a command which fills up the shorter lists with blanks?
    > Like an enhanced zip() command, maybe?
    >[/color]

    map(None, list1, list2, list3)



    Comment

    • Fredrik Lundh

      #3
      Re: Extended zip() for lists

      Florian Reiser wrote:
      [color=blue]
      > I have 4 lists: a, b, c and d
      > Out of this 4 lists I want to build a table (e.g. list of lists):
      >
      > a|b|c|d
      > ---------------------------
      > a1|b1|c1|d1
      > a1|b2| |d2
      >
      > You see: the lists are not equally sized.
      > Is there a command which fills up the shorter lists with blanks?
      > Like an enhanced zip() command, maybe?[/color]

      like map(None, ...), perhaps ?
      [color=blue][color=green][color=darkred]
      >>> a = "1234"
      >>> b = "12"
      >>> c = "123"
      >>> d = "1234"
      >>> zip(a, b, c, d)[/color][/color][/color]
      [('1', '1', '1', '1'), ('2', '2', '2', '2')][color=blue][color=green][color=darkred]
      >>> map(None, a, b, c, d)[/color][/color][/color]
      [('1', '1', '1', '1'), ('2', '2', '2', '2'), ('3', None, '3', '3'),
      ('4', None, None, '4')]

      </F>

      Comment

      • Duncan Booth

        #4
        Re: Extended zip() for lists

        Florian Reiser wrote:
        [color=blue]
        > Hello,
        >
        > I have 4 lists: a, b, c and d
        > Out of this 4 lists I want to build a table (e.g. list of lists):
        >
        > a|b|c|d
        > ---------------------------
        > a1|b1|c1|d1
        > a1|b2| |d2
        >
        > You see: the lists are not equally sized.
        > Is there a command which fills up the shorter lists with blanks?
        > Like an enhanced zip() command, maybe?
        >
        > Regards
        > Florian Reiser
        >[/color]

        I posted a function to do this back in January. See:


        Comment

        • Florian Reiser

          #5
          Re: Extended zip() for lists

          Hello Gene,

          a big THANKS for this tip. This is exactly what I was looking for.

          Regards

          Florian Reiser

          "gene tani" <gene.tani@gmai l.com> schrieb im Newsbeitrag
          news:1149772973 .297794.68720@i 39g2000cwa.goog legroups.com...[color=blue]
          >
          > Florian Reiser wrote:[color=green]
          >> Hello,
          >>
          >> I have 4 lists: a, b, c and d
          >> Out of this 4 lists I want to build a table (e.g. list of lists):
          >>
          >> a|b|c|d
          >> ---------------------------
          >> a1|b1|c1|d1
          >> a1|b2| |d2
          >>
          >> You see: the lists are not equally sized.
          >> Is there a command which fills up the shorter lists with blanks?
          >> Like an enhanced zip() command, maybe?
          >>[/color]
          >
          > map(None, list1, list2, list3)
          >
          > http://aspn.activestate.com/ASPN/Coo.../Recipe/410687
          >[/color]


          Comment

          Working...