Can this be done with list comprehension?

Karlo Lozovina _karlo_ at _mosor.net_
Sun Jun 8 00:31:25 CEST 2008


This is what I'm trying to do (create a list using list comprehesion, then 
insert new element at the beginning of that list):

  result = [someFunction(i) for i in some_list].insert(0, 'something')

But instead of expected results, I get None as `result`. If instead of 
calling `insert` method I try to index the list like this:

  result = [someFunction(i) for i in some_list][0]

It works as expected. Am I doing something wrong, or I can't call list 
methods when doing list comprehension?

P.S.
In case you're wondering, it has to be done in one line ;).


-- 
 _______                                        Karlo Lozovina - Mosor
|   |   |.-----.-----.     web: http://www.mosor.net || ICQ#: 10667163
|       ||  _  |  _  |             Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|



More information about the Python-list mailing list