looping throuhg a list 2 items at a time

Brad Bollenbach bbollenbach at shaw.ca
Wed Apr 10 21:02:22 EDT 2002


In article <a92hl1$1v4c at r02n01.cac.psu.edu>, Rajarshi Guha wrote:
[snip]
> (I could arrange the data into tuples if necessary)

There's your answer then. :)

When the choice lies between smart data structures, or poor data
structures that force you to think of ways to code around them, go with
the smart data structures.

e.g.

l = [(1,'s'), (2,'t'), (3,'d')]

for x, y in l:
    print x, y

Can't get any simpler than that.

HTH,

Brad



More information about the Python-list mailing list