How to extract 2 integers from a string in python?

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Jun 9 06:32:18 EDT 2006


Stephen Prinster  <prinster at mail.com> wrote:
>>>> a, b, c, d = 'Total size: 173233 (371857)'.split()
>>>> first_int, second_int = int(c), int(d[1:-1])

int(d[1:-1]) can be replaced by d.strip("()"), which may or
may not be clearer in intent.

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list