Avatar ·

How to change values in the list without creating a new list?

📁 Advanced Python Topics, work

The standard method using list comprehension:

my_list = [1, 2, 3, 4, 5, 6]
my_list_1 = [i*5 for i in my_list]
print(my_list_1)

Why can't I do it with the original list:

my_list = [1, 2, 3, 4, 5, 6]