(newbie)list conversion problem
Gerrit Holl
gerrit at nl.linux.org
Thu Jun 19 09:30:46 EDT 2003
Hi,
Boris Genz wrote:
> I want to translate list of strings into identical list of integers. To
> clear things up, here is an example:
> for elements in x:
> group = []
> group.append(int(elements))
Try to move the 'group = []' statement out of the for loop.
Currently, each time the block is executed, you are creating
a new empty list. You probably ended up with a list with one
integer element.
The following should work:
1.
group = []
for elem in x:
group.append(int(elem))
group = [int(elem) for elem in x]
group = map(int, x)
I prefer the second one, but they are all correct.
> P.S. My English is poor but I hope you understand me;)
I understand you perfectly - assumed I have answered your question ;)
yours,
Gerrit.
--
238. If a sailor wreck any one's ship, but saves it, he shall pay the
half of its value in money.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
More information about the Python-list
mailing list