sum and strings

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Aug 20 09:05:12 EDT 2006


In <mailman.9571.1156078160.27775.python-list at python.org>, Gerhard Fiedler
wrote:

> On 2006-08-20 07:18:44, Rhamphoryncus wrote:
> 
>>> shallow = []
>>> [shallow.extend(i) for i in deep]
>> 
>> I'm sure this has been mentioned before, but listcomps are for when you
>> want to store the list and use it for further things, not for when you
>> want a side effect.  TOOWTDI.
> 
> Can you please explain what you mean with this, and maybe why?

You should not abuse list comps just to have a one liner.  Only use them
if you really want to build a list and not just for side effects.  The
above one-liner builds a list of `None`\s of length ``len(deep)`` for no
reason just to throw them away.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list