+ 1
Replace a number in a list by X
Hello! Can someone help me, I want to replace the number that is input by the user by a X in the list https://code.sololearn.com/cyNo0xaU1vdS/?ref=app
5 odpowiedzi
+ 4
Jay Matthews FYI, you could use the index method like so:
l = [2,4,6,8,9,10,12,4,16,18,20]
num = int(input("Enter a numer: "))
while n in l:
l[l.index(n)] = 'X'
print(l)
this way will get and replace all occurrences without the need to use the insert and remove methods.
+ 1
I was looking that if I enter as input 4, when I print the list be like [2, X, 6, 8, 10, 12, 14, 16, 18, 20]
0
Though not a list,the result will truly look like that
0
Xxx