+ 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

26th Nov 2020, 12:49 AM
Alejandra b
Alejandra b - avatar
5 Respuestas
+ 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.
26th Nov 2020, 4:20 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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]
26th Nov 2020, 1:04 AM
Alejandra b
Alejandra b - avatar
0
Though not a list,the result will truly look like that
27th Nov 2020, 2:40 PM
yingSSS['book'=="本"]
0
Xxx
27th Nov 2020, 8:42 PM
Ramiro Arredondo
Ramiro Arredondo - avatar
27th Nov 2020, 2:35 PM
yingSSS['book'=="本"]