looping throuhg a list 2 items at a time
Rajarshi Guha
rxg218 at psu.edu
Wed Apr 10 18:42:34 EDT 2002
Hi,
I have a list like this: l = [1,'s', 2,'t', 3,'d']
I'd like to loop through the list but within the loop I want
the current element and the element just after it:
I tried this
liter = iter(l)
for i in l:
print i, liter.next()
But I get:
1 1
s s
2 2
t t
3 3
d d
whereas I want
1 s
2 t
3 d
I can see I'm wrong - any ideas on how to fix it?
TIA,
--
Rajarshi Guha
rajarshi at presidency.com
More information about the Python-list
mailing list