0

How can I change a number in list? (Python)

I tried it with enumerate but it does not work. list = [30, 20, 10] for n, i in enumerate(list): if i == 20: list[n] = 25

21st Apr 2019, 5:53 PM
Steve Chris
Steve Chris - avatar
4 Antworten
+ 3
The problem is not enumerate but list. You overwrite the built-in type list by calling your list like that. Name it list_ and your code works. About your naming: The index should be i and the number n.
21st Apr 2019, 6:35 PM
HonFu
HonFu - avatar
+ 3
add a print(list) at the end out side of the loop and you see that your code did work
21st Apr 2019, 6:32 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
Okay. Thank you.
21st Apr 2019, 6:45 PM
Steve Chris
Steve Chris - avatar
0
Yea.. right with print(list) ... 😅
21st Apr 2019, 7:05 PM
Steve Chris
Steve Chris - avatar