ordered sets operations on lists..
Alex Martelli
aleaxit at yahoo.com
Sun Feb 12 14:50:02 EST 2006
Bengt Richter <bokr at oz.net> wrote:
...
> >Personally, I'd always use (depending on guesses regarding lengths of
> >lists) [x for x in l1 if x in l2] or the setified equivalent, of course.
> >
> Perhaps newbies should be advised that
>
> [x for x in l1 if x in set(l2)]
>
> is not a (well) setified equivalent? I could see them being tempted.
You mean, newbies should be advised that Python does NOT hoist any
computations whatsoever from the body of a loop (including LCs and
genexps), so if you want anything hoisted you need to hoist it yourself?
Yes, it is a point worth making, since the lack of hoisting is a
frequent cause of performance loss.
Alex
More information about the Python-list
mailing list