looping over more than one list
Dylan Moreland
dylan.moreland at gmail.com
Thu Feb 16 10:18:16 EST 2006
> def lowest(s1,s2):
> s = ""
> for c1,c2 in [x for x in zip(s1,s2)]:
> s += lowerChar(c1,c2)
> return s
>
> but it's hardly any more elegant than using a loop counter, and I'm
> guessing it's performance is a lot worse - I assume that the zip
> operation is extra work?
>
> Iain
Always look in itertools for stuff like this:
http://docs.python.org/lib/itertools-functions.html#l2h-1392
for c1, c2 in itertools.izip(s1, s2):
...
I haven't profiled it, but it makes sense that this would be fast.
More information about the Python-list
mailing list