Looping on more than one list
Peter Schneider-Kamp
peter at schneider-kamp.de
Sun Jul 23 02:41:15 EDT 2000
ahmed Bouferguene wrote:
>
> a = [1,2,34]
> b=["a", "b", "d"]
>
> for x in a, y in b :
> print x, y
>
> and the loop exits when the shortest list is exhausted
minlen = min(len(a), len(b))
for x,y in map(None, a[:minlen], b[:minlen]):
print x, y
In Python 2.0 you will probably be able to do:
for x,y in zip(a,b):
print x, y
Peter
--
Peter Schneider-Kamp ++47-7388-7331
Herman Krags veg 51-11 mailto:peter at schneider-kamp.de
N-7050 Trondheim http://schneider-kamp.de
More information about the Python-list
mailing list