Let’s say I have a list like:
my_list = [[1,2,3],[4,5,6],[7,8,9]]
How do I alter every value in the list without doing?:
for x in range(0, 3): for y in range(0, 3): my_list[x][y] = -my_list[x][y]
I have tried to simplify this by doing
my_list = [[[-a, -b, -c] for [a, b, c] in d] for d in my_list]
but the values remain the same.
Many answers are about creating altered copy of list, but literal meaning of question is about in-place modification of list.
Here is my version of best-of-breed in-place list altering solution:
Test run:
No list copies. No hardcoded bounds. No list comprehensions with side-effects.