Misuse of list comprehensions?
Paul Hankin
paul.hankin at gmail.com
Tue May 20 12:08:25 EDT 2008
On May 20, 3:58 pm, Paul McGuire <pt... at austin.rr.com> wrote:
> def compress(s):
> seen = set()
> return ''.join(c for c in s if c not in seen and (seen.add(c) or
> True))
Slightly nicer is to move the set add out of the conditional...
def compress(s):
seen = set()
return ''.join(seen.add(c) or c for c in s if c not in seen)
I wouldn't write it this way though :)
--
Paul Hankin
More information about the Python-list
mailing list