-6

Assumed I have string : 0²0 36 0 ² 6 4

How can I convert it into string : 020360264

2 Answers2

1
s = "0²0 36 0 ² 6 4"
s = s.replace("²", "2")  # replace the funky 2
s = "".join(c for c in s if c.isdigit())  # keep digits only
print(s)

Outputs, as expected, 020360264

AKX
  • 123,782
  • 12
  • 99
  • 138
0

this is a variant:

strg = "0²0 36 0 ² 6 4"
strg = strg.translate(str.maketrans({"²": "2", " ": None}))
# 020360264

using str.maketrans and str.translate to remove all the spaces and convert '²' to '2'.

hiro protagonist
  • 40,708
  • 13
  • 78
  • 98