I have a list like this:
mylist = [("elem","str"), ("123","int"),("1.0","float")]
For each tuple, the first element is the data, and the second element is the original type of that data, so I want to convert it to it.
As a result, I want:
mylist = ["elem",123,1.0]
How can I dynamically convert an object given the target data type?
I want to avoid this:
for el in mylist:
if el[1]=="str":
result=el[0]
elif el[1]=="int":
result=int(el[0])
elif el[1]=="float":
result=float(el[0])