List comprehensions' ugliness (Was: Re: How to explain exactly what "def" does?)

Donnal Walter donnal at donnal.net
Thu Feb 6 10:46:27 CET 2003


Alex Martelli wrote:
> Hans Nowak wrote:
>    ...
> 
>>   [mylist.append(z) for z in otherlist]
>>
>>The point of list comprehensions is to return a list, and the example
>>above doesn't do anything with that list.  It's better written as
>>
>>   for z in otherlist:
>>       mylist.append(z)
> 
> 
> mylist.extend(otherlist) is better.
> 

mylist = mylist + otherlist

The above assignment statement is an idiom that I have (perhaps naively) 
adopted. Is the .extend syntax more efficient? I can also see where it 
might be considered more readable or more accurate. (?)

Donnal Walter
Arkansas Children's Hospital







More information about the Python-list mailing list