On 03/20/2011 09:44 PM, bearophile wrote:
>          # Logically, the following should produce a copy:
>          [x in coll]                        # dont work
Your logic is broken.

I don't think so ;-) This is something I discussed on Python's design mailing list ("ideas"). The only reason why this is not possible to implement in python is that 'in' is also the membership operator. So that [x in coll] evaluates to [true] or [false]. Just replace 'in' by another keyword in the expression of list comprehensions, and, I guess, you won't find it broken:
        # filter only:
        negs = [x across coll if x<1]
instead of
        # current syntax forces mapping with identity function
        # in addition to filter:
        negs = [x for x in coll if x<1]

What's really weird is that mapping without filter is indeed possible; one is not forced to write:
        squares = [x*x for x in coll if true]
lol!

Denis
--
_________________
vita es estrany
spir.wikidot.com

Reply via email to