[Tutor] Yet another list comprehension question
David Perlman
dperlman at wisc.edu
Fri Mar 2 18:23:51 CET 2007
On Mar 2, 2007, at 9:56 AM, Alan Gauld wrote:
> Why not use a Set?
>
> s = Set([somefun(i) for i in some-iterator])
>
> Might be slow for big lists though...
I'm curious why using a Set would be slower than doing it in a loop?
In either case, the processor has to scan through all the data
looking for duplicates. I suppose in this case it's doing it in two
passes, though. On the other hand, the "not in l" check has to scan
through the whole l each time.
I'd be really interested in seeing benchmarks comparing the
methods... no time to do it myself though... :)
--
-dave----------------------------------------------------------------
Science arose from poetry... when times change the two can meet again
on a higher level as friends. -Göthe
More information about the Tutor
mailing list