Misuse of list comprehensions?

Lie Lie.1296 at gmail.com
Tue Jun 3 12:22:35 CEST 2008


On May 20, 8:51 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> bearophileH... at lycos.com wrote:
> > John Salerno:
> >> What does everyone think about this?
>
> > The Example 2 builds a list, that is then thrown away. It's just a
> > waste of memory (and time).
>
> No, it doesn't. It uses append because it refers to itself in the
> if-expression. So the append(c) is needed - and thus the assignment
> possible but essentially useless.
>
> Diez

Yes it does, it build a list of 'None's.

And if list.append is concerned, the example given has no use, since:
x = [c for c in cs]
is essentially the same as
x = []
[x.append(c) for c in cs]

If, you're talking about other function calls, it might be an abuse or
not depending on personal preference.



More information about the Python-list mailing list