Xodarap777 Xodarap777 - 1 year ago 76
Python Question

Reversing str.translate in Python

If I want to remove the numbers from "He123llo Wor456ld!" with translate, I can

from string import digits
str = "He123llo Wor456ld!"
str = str.translate(None, digits)
print str

>> Hello World!

How would I reverse this to get
via translate?

Answer Source

You could use something like this

from string import digits
s = "He123llo Wor456ld!" 
s_ = s.translate(None, digits)
s = s.translate(None, s_)
print s

>>> 123456
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download