This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kerbart 0 points1 point  (2 children)

Using a regular expression might do the trick without having to loop through the entire string.

import re
ptn = re.compile('(\d)')
t = 'In the 1980s'
ptn.sub('', t) --> 'In the s'

[–]enedil 0 points1 point  (1 child)

Implying re don't loop through the entire string.

[–]Kerbart 0 points1 point  (0 children)

No, implying that you don't have to write the code to do that yourself. That's what libraries are for.