[Tutor] Yet another list comprehension question

Alan Gauld alan.gauld at btinternet.com
Fri Mar 2 16:56:52 CET 2007


"Smith, Jeff" <jsmith at medplus.com> wrote

> In other words, applying somefun to the results of the iterator 
> return
> duplicates but I want the constructed list to contain none.

> l = [somefun(i) for i some-iterator if somefun(i) not in l]
>
> doesn't work (not that I expected it to).

Why not use a Set?

s = Set([somefun(i) for i in some-iterator])

Might be slow for big lists though...

Alan g 




More information about the Tutor mailing list