How to extract 2 integers from a string in python?
prinster at mail.com
Fri Jun 9 01:13:59 EDT 2006
yinglcs at gmail.com wrote:
> how can I extract 2 integers from a string in python?
> for example, my source string is this:
> Total size: 173233 (371587)
> I want to extract the integer 173233 and 371587 from that soource
> string, how can I do that?
Use split() to split the string into four strings, using spaces as
separators, then use int() to convert the resulting strings that
>>> a, b, c, d = 'Total size: 173233 (371857)'.split()
>>> first_int, second_int = int(c), int(d[1:-1])
More information about the Python-list