On or about 2009 Sep 10, at 11:36 AM, Serdar Tumgoren indited:
I think a list comprehension might be the most compact way to
accomplish what you're after:

objcts = [a, b, c]

titles = [obj.title for obj in objcts]

That probably is the best form.


For the sake of showing other options:

from operator import attrgetter
#...
titles = map(attrgetter("title"), objcts)


# I love placeholder for this kind of thing.
from placeholder import __
#...
titles = map(__.title, objcts)

--Doug

P.S. placeholder can be found at: http://pypi.python.org/pypi/placeholder
P.P.S. I have a version that composes, so you can say: map((__ + 3) * 2, my_numbers) -- http://bitbucket.org/dgou/placeholder2/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to