g = [('Books', '10.000'),('Pen', '10'),('test', 'a')]
Here '10.000'
and '10'
are strings
How to convert to below format, string to float
Expected out
[('Books', 10.000),('Pen', 10),('test', 'a')]
Here 10.000
and 10
are floats and a
has to be string
newresult = []
for x in result:
if x.isalpha():
newresult.append(x)
elif x.isdigit():
newresult.append(int(x))
else:
newresult.append(float(x))
print(newresult)
I got error AttributeError: 'tuple' object has no attribute 'isalpha'