list comprehention

Morten Vold morten.vold at
Tue Jan 24 03:23:56 EST 2006

On 23/01/2006 18:41, Mathijs uttered:

>> len([ref.pop(ref.index(x)) for x in lis if x in ref])

> This is the type of solution I was hoping to see: one-liners, with no
> use of local variables. As Tim Chase already wrote, it has only one
> less elegant side: it alters the original ref list.
> Thanks for your suggestion.

May I suggest another one-liner:


I have no idea how this scales/performs compared to the other
suggestions you've received, but I find it immediately comprehensible.

-- Morten

More information about the Python-list mailing list