Need an identity operator because lambda is too slow
Gabriel Genellina
gagsl-py at yahoo.com.ar
Mon Feb 19 00:02:55 EST 2007
En Sun, 18 Feb 2007 23:31:53 -0300, Sean McIlroy <sean_mcilroy at yahoo.com>
escribió:
> On Feb 17, 9:59 pm, "Deron Meranda" <deron.mera... at gmail.com> wrote:
> [snip]
>
> this may be really dense, but i'm curious what's wrong with the
> "multiplexer" idiom:
>
> for item in some_sequence:
> item2 = (not some_rare_condition and item) or \
> (some_rare_condition and
> some_transform_function(item))
> ..... # more stuff
The main concern of the OP was that lambda x:x is slow, so it's better to
move the condition out of the loop.
Also, this and/or trick does not work when the Boolean value of item is
false (like 0, (), []...)
--
Gabriel Genellina
More information about the Python-list
mailing list