I have a list of objects with a method, say cleanup()
, that I need to invoke on all of them. I understand there are at least two ways:
map(lambda x: x.cleanup(), _my_list_of_objects)
or
for x in _my_list_of_objects:
x.cleanup()
My question(s):
- Is one more Pythonic than the other?
- Are there other better ways? I see the former being used often in the code base (at work) here, but it bugs me that map constructs and returns a list that is then thrown away (right?).
- Is the perf impact (of a list that is immediately GC'd) something to consider?