How to parsing a sequence of integers

Steven Woody narkewoody at gmail.com
Fri Dec 19 14:50:12 CET 2008


On Fri, Dec 19, 2008 at 9:33 PM, Bruno Desthuilliers
<bruno.42.desthuilliers at websiteburo.invalid> wrote:
> Steven Woody a écrit :
>>
>> 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()?
>
> source = "123 100 12 37"
> list_of_ints = [int(part) for part in source.strip().split()]
>
>>
>> In additional to max/min, is there something like average()?
>
> Not AFAIK, but it's really trivial
>
> def average(lst):
>   """ assume lst is a list of numerics """
>   return sum(lst) / len(lst)
>

Cool! Thank all of you.



More information about the Python-list mailing list