I have a list of objects, and I'd like to go through each object and change an attributed. Is there a difference in memory usage between (1) map lambda and (2) going through the list objects one by one.
Here is a simple example code
class F(object):
def __init__(self):
self.ID = 0
def set_ID(self):
self.ID = 1
number = 1000000
list_objects = [F() for i in xrange(n)]
There are two ways of using set_ID:
One way
map(lambda x: x.set_ID(), list_objects)
Another way
for obj in list_objects:
obj.set_ID()