Replace values in list using Python
Build a new list with a list comprehension: You can modify the original list in-place if you want, but it doesn’t actually save time: Here are (Python 3.6.3) timings demonstrating the non-timesave: And Python 2.7.6 timings: