I\'m trying to learn Python and i have a problem, so if i have something like that:
data_l = [\'data\', \'18.8\', \'17.9\', \'0.0\']
How d
Universal approach:
def validate_number(s):
try:
return float(s)
except (ValueError, TypeError):
return s
data = [validate_number(s) for s in data]
In case the structure is fixed:
data = [s if i == 0 else float(s) for i, s in enumerate(data)]
Another one:
data = [data[0]] + [float(s) for s in data[1:]]
isdigit would work in case of positive integers:
data = [int(s) if s.isdigit() else s for s in data]