[Pythonmac-SIG] inputing multi-digit numbers

Dethe Elza delza at livingcode.org
Thu Nov 10 18:52:37 CET 2005


>> Question: how do I get rid of the \n attached to each member in my  
>> list?
>
> Choose:
>
> map(int(map(string.strip, yourlist)) (Python 2.2)
>
> [ int(x.strip()) for x in yourlist ] (Python 2.3)
>
> ( int(x.strip()) for x in yourlist ) (Python 2.4)
>

You don't need strip(), int() ignores white space. So the generator- 
expression version could be (others could be shortened similarly):

(int(x) for x in yourlist)

--Dethe

A miracle, even if it's a lousy miracle, is still a miracle.  --Teller




More information about the Pythonmac-SIG mailing list