Misuse of list comprehensions?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue May 20 10:10:32 EDT 2008


John Salerno a écrit :
> I posted this code last night in response to another thread, and after I 
> posted it I got to wondering if I had misused the list comprehension. 

(snip)
> def compress(s):
>     new = []
>     [new.append(c) for c in s if c not in new]
>     return ''.join(new)

As far as I'm concerned (and I'm a big fan of list-comps, generator 
expressions etc), this is definitively an abuse. And a waste of 
resources since it builds  a useless list of 'None'.



More information about the Python-list mailing list