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\"] <
[\"hello\", \"3\", \"3.64\", \"-1\"]
import ast L = ["hello", "3", "3.64", "-1"] def tryeval(val): try: val = ast.literal_eval(val) except ValueError: pass return val print [tryeval(x) for x in L]