What is wrong with this code? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What is wrong with this code?

I am testing out regex to replace a list of numbers I don't know if it has ever been done before so. I want to replace 3 in the list with 11 And 4 in the list with 12 Using regex Is there any way to do this? import re list = [3,4] newlist = [re.sub(r/d/3, 11, list)] print(newlist) https://code.sololearn.com/cTyUB90i2HcL/?ref=app

14th Apr 2021, 5:49 PM
Steve Nova
Steve Nova - avatar
2 Respostas
+ 1
Regex is used to edit strings. Itā€™s not designed to edit integer data or other data types. If you had a string like ā€œI have 3 apples.ā€ You could replace the 3 with 11 in that string.
14th Apr 2021, 5:58 PM
Jerry Hobby
Jerry Hobby - avatar
0
Jerry Hobby thank for clearing that out
14th Apr 2021, 6:01 PM
Steve Nova
Steve Nova - avatar