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 Answers
+ 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