[Tutor] Iterating over multiple lists- options
Alan Gauld
alan.gauld at freenet.co.uk
Mon Feb 7 20:56:41 CET 2005
> How about using a try loop every time you read from
> the list.
try is not a loop.
> try:
> x=list[someno]
> except:
> x=nothing(or whatever)
>
> This goes on till the all lists start returning none.
No, sorry it just does it once.
try/except is for detecting errors not a looping construct.
> for shorter lists try throws an index out of range
> exception which is caught by except.
This much is true. But to do as you suggest the try/except
would need to be placed inside a for or while loop. However
that would be an interesting approach. I don't know if it
would be faster than comparing the len(), I suspect not,
but try/except is fairly fast so it just might be.
Alan G.
More information about the Tutor
mailing list