How to parsing a sequence of integers

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Dec 19 14:32:31 CET 2008


On Fri, 19 Dec 2008 21:20:48 +0800, Steven Woody wrote:

> Hi,
> 
> I am a newbie and is reading the python book.  Could anyone tell me, how
> to parsing the following string
>    "123 100 12 37 ..."
> into a list of integers on which I can then apply max()/min()?

In [376]: '123 100 12 37'.split()
Out[376]: ['123', '100', '12', '37']

In [377]: map(int, '123 100 12 37'.split())
Out[377]: [123, 100, 12, 37]

In [378]: max(map(int, '123 100 12 37'.split()))
Out[378]: 123

> In additional to max/min, is there something like average()?

No, but it's easy to implement with `sum()`, `len()` and ``/``.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list