(newbie)list conversion problem

rzed Dick.Zantow at lexisnexis.com
Thu Jun 19 09:27:43 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, and here is what I tried:
> x = ['7659', '33', '454', '445']
> for elements in x:
>   group = []
>   group.append(int(elements))
>
> and I got gibberish:) I'm obviously doing something wrong. Can you
> help me please, I appreciate any help...
>
> P.S. My English is poor but I hope you understand me;)

I suppose you got
[445]
as the value of group. That's not gibberish, it's what you asked for.
For each element in x, you have a new list to which you append one
element. If you take "group = []" out of the loop, you will get what
you want.

--
rzed






More information about the Python-list mailing list