zip unzip?

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

    #1

    zip unzip?

    I have two lists...

    a=[1,2,3]
    b=[4,5,6]

    n=0
    for i in a:
    print i, b[n]
    n=n+1

    how can i have two iterators on my for loop?
    rather than have to use the counter n?
    like:
    for i,j in a,b:
    print i, j

    Do you know what I mean?

  • ZeD

    #2
    Re: zip unzip?

    Ciao, KraftDiner! Che stavi dicendo?
    [color=blue]
    > I have two lists...
    >
    > a=[1,2,3]
    > b=[4,5,6]
    >
    > n=0
    > for i in a:
    > print i, b[n]
    > n=n+1
    >
    > how can i have two iterators on my for loop?[/color]

    for i,j in zip(a,b):
    print i,j

    --
    Quante sono le persone
    che sanno leggere il codice esadecimale,
    se ci sono de11e persone
    che sanno leggere il codice esadecimale?

    Comment

    • Fredrik Lundh

      #3
      Re: zip unzip?

      KraftDiner wrote:
      [color=blue]
      > I have two lists...
      >
      > a=[1,2,3]
      > b=[4,5,6]
      >
      > n=0
      > for i in a:
      > print i, b[n]
      > n=n+1
      >
      > how can i have two iterators on my for loop?
      > rather than have to use the counter n?
      > like:
      > for i,j in a,b:
      > print i, j
      >
      > Do you know what I mean?[/color]

      given your subject line, you seem to know what you mean.

      for i,j in zip(a,b):
      print i, j

      </F>



      Comment

      Working...