On Fri, 19 Dec 2008 04:26:16 -0800, bearophileHUGS wrote:
> Peter Otten:
>> The problem is that list comprehensions do not introduce a new
>> namespace.
>
> I think Python3 fixes this bug.
Or removes that feature. ;-)
--
http://mail.python.org/mailman/listinfo/python-list
Peter Otten:
> The problem is that list comprehensions do not introduce a new namespace.
I think Python3 fixes this bug.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Peter Otten wrote:
> The problem is that list comprehensions do not introduce a new namespace. So
> the inner and the outer list comp share the same i. You can either rename
> the inner i
>
[i for i in a if i not in [k for k in b]]
> ['b']
>
> or use a generator expression which does give a
Vedran Furac( wrote:
> Hi!
>
> In [69]: a = 'a b c'
> In [70]: b = 'a b, c d'
>
> In [74]: [i for i in a.split() if i not in b.split()]
> Out[74]: ['b']
>
> Everything ok.
>
> In [77]: b.split() == [i for i in b.split()]
> Out[77]: True
>
> As expected. Now, put this in the first list compreh