I am trying to replace the value 11 with the value of 1.
What am I doing wrong?
I want it to be:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
I am trying to replace the value 11 with the value of 1.
What am I doing wrong?
I want it to be:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
In your exampe i
is an item in list, not an index:
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
for i, val in enumerate(cards):
if val == 11:
cards[i] = 1
print(cards)
You could do this with a list comprehension:
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
[1 if i==11 else i for i in cards]
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]