How do I insert a list (or numpy array) containing attribute values into a list of objects (as shown below)?
class myClass(object):
def __init__(self, attr):
self.attr = attr
self.other = None
objs = []
for i in range(10):
objs.append(myClass(i))
attrs = [o.attr for o in objs]
print attrs
#[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[o.attr for o in objs] = range(10)
#SyntaxError: can't assign to list comprehension
This is the inverse problem to Extract list of attributes from list of objects in python.