Can this be done with list comprehension?

Terry Reedy tjreedy at
Sat Jun 7 20:27:54 EDT 2008

"Karlo Lozovina" <_karlo_ at _mosor.net_> wrote in message 
news:Xns9AB7858EC056mosornet at
| I figured that out few minutes ago, such a newbie mistake :). The fix I
| came up with is:
|  result = ['something'] + [someMethod(i) for i in some_list]
| Are there any other alternatives to this approach?

result = [something]
result.extend(someMethod(i) for i in some_list)

avoids creating and deleting an intermediate list 

More information about the Python-list mailing list