[Tutor] Finding items in list of lists.
Doug.Shawhan@gecits.ge.com
Doug.Shawhan@gecits.ge.com
Tue Mar 18 09:48:06 2003
"Reduce", my new favorite action now that I have grown used to "zip". :-)
> Hi Doug!
> You could mix it with something "less friendly" (???) and first
> flatten your list of lists l by using reduce:
> from operator import add
> >>> reduce(add,l)
> ['joe', 'moe', 'schmoe', 'fee', 'foo', 'bar']
> With this a single comprehension would do it:
> >>> [y for y in reduce(add,l) if y in ("moe", "foo")]
> ['moe', 'foo']
> >>>
> Regards, Gregor