(newbie)list conversion problem

Bruno Desthuilliers bdesth.nospam at removeme.free.fr
Thu Jun 19 15:10:54 EDT 2003


Boris Genz wrote:
> Ok, I know this problems proabably make you laugh, but I'm in learning
> process:)
> I want to translate list of strings into identical list of integers. To
> clear things up, here is an example:
> I want this list: ['7659', '33', '454', '445'] to change in something
> like this: [7659, 33, 454, 445].
> I'm sure this is possible,
Of course

> and here is what I tried:
> x = ['7659', '33', '454', '445']
> for elements in x:
>   group = []

Here you rebind 'group' to an empty list in each turn of the loop...

>   group.append(int(elements))
> 
> and I got gibberish:) 

I guess you have something like group => [445] ?

> I'm obviously doing something wrong. Can you help
> me please, I appreciate any help...
> 

Have you tried :
group = [int(item) for item in x]

HTH
Bruno Desthuilliers





More information about the Python-list mailing list