Not a big fan of this, but you can try this (although I think that all of the above is much more concise and easy to read):
In [22]: from operator import setitem In [23]: mylist = [0, 0, 0, 0, 0] In [24]: indeces_to_replace = [0, 1, 3] In [25]: _ = map(lambda x: setitem(mylist, x, 100), indeces_to_replace) In [26]: mylist Out[26]: [100, 100, 0, 100, 0]
Besides dubious readability and the need to import, @abarnert pointed out a few additional problems, namely that map still creates an unnecessary list (which is discarded with _ but nonetheless created) and that it wonโt work in Python 3, because that map returns an iterator in Python 3.x. You can use the six module to model map behavior in Python 3.x from Python 2.x and in combination with collections.deque (again, as @abarnert suggested), you can get the same result without creating an extra list in memory , because deque , which can contain a maximum of 0 elements, will discard everything it receives from the map iterator (note that with six , map modeled using itertools.imap ).
Again, there is absolutely no need to ever use this - every solution above / below is better :)
In [1]: from collections import deque In [2]: from six.moves import map In [3]: from operator import setitem In [4]: mylist = [0, 0, 0, 0, 0] In [5]: indeces_to_replace = [0, 1, 3] In [6]: deque(map(lambda x: setitem(mylist, x, 100), indeces_to_replace), maxlen=0) Out[6]: deque([], maxlen=0) In [7]: mylist Out[7]: [100, 100, 0, 100, 0]