Misuse of list comprehensions?

Arnaud Delobelle arnodel at googlemail.com
Tue May 20 12:50:31 EDT 2008


Paul McGuire <ptmcg at austin.rr.com> writes:

> On May 20, 10:17 am, Arnaud Delobelle <arno... at googlemail.com> wrote:
[...]
>> <split hairs>
>> Isn't
>>
>>     c not in seen and (seen.add(c) or True)
>>
>> the same as
>>
>>     seen.add(c) or c not in seen
>>
>> ?
>>
>> >     return ''.join(new)
>>
>> (notice I haven't closed the tag!)
>>
>> --
>> Arnaud- Hide quoted text -
>>
>> - Show quoted text -
>
> Unfortunately, no.  "seen.add(c) or c not in seen" will never return
> true, since c gets added to seen before testing if c in seen.
>
> -- Paul

Ha you're right of course.  But I haven't closed the tag yet, so:

    c not in seen and (seen.add(c) or True)

is definitely the same as

    c not in seen and not seen.add(c)

which is

    not (c in seen or seen.add(c))

:)

</split hairs>

-- 
Arnaud



More information about the Python-list mailing list