HowTo Search in nested lists

Anton Vredegoor anton at vredegoor.doge.nl
Sat Jan 31 10:05:04 CET 2004


Christopher Koppler <klapotec at chello.at> wrote:

[Robert]
>>Good answers, Christopher. You might consider combining the several
>>approaches into a single one by creating an iterator;

>Well, just what popped into my mind first. I still have some trouble
>getting iterators and generators to pop up before, though often
>they're just so much more elegant, as your solution shows. But for
>that I have to consciously think about the problem, whereas ordinary
>functions are quite entrenched in my brain. I blame my shady past of
>Pascal, Visual Basic, Modula 2, C, and Java. At least by now I
>instantly think of list comprehensions...

One might also consider the following solution which swaps rows and
columns by combining the star operator and the zip function :

print [i for i,col in enumerate(zip(*t)) if 5 in col]

Anton




More information about the Python-list mailing list