-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
  • 152,115
  • 15
  • 115
  • 172
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
  • 44,693
  • 14
  • 86
  • 111