[Tutor] casting string to integer in a list of lists
culpritNr1
ig2ar-saf1 at yahoo.co.uk
Fri Jan 9 19:24:20 CET 2009
Hello Kent and All,
Errata: int() does work.
I think that in my test code a number such as '4.5' might have slipped in
and then int() protested.
eval() worked in all my attempts. So, thanks Daniel Sarmiento, your solution
is correct as is.
By the way, when I said 'cast' I really meant 'convert'. Sorry, my badness.
Thanks for pointing that out.
culpritNr1
Kent Johnson wrote:
>
> On Fri, Jan 9, 2009 at 11:23 AM, culpritNr1 <ig2ar-saf1 at yahoo.co.uk>
> wrote:
>> That is EXACTLY what I was looking for.
>>
>> Actually, int() does not really work but this does:
>>
>> [ [line[0], eval(line[1]), eval(line[2])] + line[3:] for line in LoL]
>
> That's strange. What happened when you tried int() ? What version of
> Python are you using?
>
> Kent
>
> PS Please subscribe to the list
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
View this message in context: http://www.nabble.com/casting-string-to-integer-in-a-list-of-lists-tp21359600p21377706.html
Sent from the Python - tutor mailing list archive at Nabble.com.
More information about the Tutor
mailing list