python - best way to get an integer from string without using regex -
i integers string (the 3rd one). preferable without using regex.
i saw lot of stuff.
my string:
xp = '93% (9774/10500)'
so code return list integers string. desired output be: [93, 9774, 10500]
some stuff doesn't work:
>>> new = [int(s) s in xp.split() if s.isdigit()] >>> print new [] >>> int(filter(str.isdigit, xp)) 93977410500
since problem have split on different chars, can first replace that's not digit space split, one-liner :
xp = '93% (9774/10500)' ''.join([ x if x.isdigit() else ' ' x in xp ]).split() # ['93', '9774', '10500']
Comments
Post a Comment