suppose have string such :
string = 'this string 22 not yet perfect1234 , 123pretty can be.'
i want remove numbers which mixed words, such 'perfect1234'
, '123pretty'
, but not '22'
, string , output follows:
string = 'this string 22 not yet perfect , pretty can be.'
is there way in python using regex or other method? appreciated. thank you!
s = 'this string 22 not yet perfect1234 , 123pretty can be.' new_s = "" word in s.split(' '): if any(char.isdigit() char in word) , any(c.isalpha() c in word): new_s += ''.join([i in word if not i.isdigit()]) else: new_s += word new_s += ' '
and result:
'this string 22 not yet perfect , pretty can be.'
Comments
Post a Comment