HowTo Search in nested lists

Christopher Koppler klapotec at
Sat Jan 31 06:24:49 CET 2004

On Fri, 30 Jan 2004 11:11:47 -0800, "Robert Brewer"
<fumanchu at> wrote:

>Florian Lindner wrote:
>> >I've two nested lists which are representing a table or matrix.
>> >Now I found to search for certain values in a certain column.
>> >For example: column 1, search for 5, return 1, because 5 is 
>> >found in the first column of the second element of t
>Christopher Koppler replied:
>> ...let's make a function of it that returns the list(s)
>> (in case you have more than one list fitting your search
>> criteria) containing the searched for value.
>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...


More information about the Python-list mailing list