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

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -