Style in list comprehensions

Tim Lesher tim at lesher.ws
Fri Aug 15 15:16:26 EDT 2003


Suppose I have a list of objects and I want to call a method on each. 
I can do the simple:

for i in objs:
    i.meth(arg1, arg2)

or using list comprehensions:

[i.meth(arg1, arg2) for i in objs]

The second feels more Pythonic, but do I incur any overhead for
creating the list of results when I'm not going to use it?

-- 
Tim Lesher
tim at lesher.ws




More information about the Python-list mailing list