Thomas Bellman wrote: > "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > >> [EMAIL PROTECTED] wrote: > >>> 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. > > Yes it does. A list comprehension *always* creates a list. In > this case it will be a list of None, since that is what list.append() > returns. See this:
Yep - no idea how that slipped me. I still don't mind the occasional waste of a list-creation over a more concise looping-construct, but I totally admit that one has to be aware of this. more than I was.... Diez -- http://mail.python.org/mailman/listinfo/python-list