How to extract from a list of objects a list of specific attribute?
Solution 1:
A list comprehension would work just fine:
[o.my_attr for o in my_list]
But there is a combination of built-in functions, since you ask :-)
from operator import attrgetter
map(attrgetter('my_attr'), my_list)
Solution 2:
are you looking for something like this?
[o.specific_attr for o in objects]
Solution 3:
The first thing that came to my mind:
attrList = map(lambda x: x.attr, objectList)
Solution 4:
Assuming you want field b
for the objects in a list named objects
do this:
[o.b for o in objects]