converting python list of strings to their type

Posted by user248237 on Stack Overflow See other posts from Stack Overflow or by user248237
Published on 2010-05-18T17:47:12Z Indexed on 2010/05/18 17:50 UTC
Read the original article Hit count: 179

Filed under:
|
|

given a list of python strings, how can I automatically convert them to their correct type? Meaning, if I have:

["hello", "3", "3.64", "-1"]

I'd like this to be converted to the list

["hello", 3, 3.64, -1]  

where the first element is a stirng, the second an int, the third a float and the fourth an int.

how can I do this? thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about scipy