Python: map in place

johannix picture johannix · Jun 8, 2010 · Viewed 11.6k times · Source

I was wondering if there is a way to run map on something. The way map works is it takes an iterable and applies a function to each item in that iterable producing a list. Is there a way to have map modify the iterable object itself?

Answer

John La Rooy picture John La Rooy · Nov 10, 2010

A slice assignment is often ok if you need to modify a list in place

mylist[:] = map(func, mylist)