ordered sets operations on lists..
Steve Holden
steve at holdenweb.com
Sun Feb 12 23:15:53 EST 2006
Alex Martelli wrote:
> 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.
>
Of course now 2.5 is planning to include the AST parser there's fruitful
ground for optimization studies that will perform hoisting automatically
(should anyone be looking for a project ;-)
Given that Python 2.4 doesn't even perform simple constant folding for
arithmetic expressions
>>> dis.dis(compile("print 1+2", '', 'exec'))
1 0 LOAD_CONST 0 (1)
3 LOAD_CONST 1 (2)
6 BINARY_ADD
7 PRINT_ITEM
8 PRINT_NEWLINE
9 LOAD_CONST 2 (None)
12 RETURN_VALUE
even hoisting could be seen as an "advanced" optimization.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list