loops - Extract list of attributes from list of objects in python -


i have uniform list of objects in python:

class myclass(object):     def __init__(self, attr):         self.attr = attr         self.other = none  objs = [myclass (i) in range(10)] 

now want extract list attribute of class (let's attr), in order pass function (for plotting data example)

what pythonic way of doing it,

attr=[o.attr o in objsm] 

?

maybe derive list , add method it, can use idiom like

objs.getattribute("attr") 

?

you can write:

attr=(o.attr o in objsm) 

this way generator conserves memory. more benefits @ generator expressions.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -