I have this list:
array = ['Katherine', '999', '333']
I need to convert the '999'
and '333'
into floats.
The list should look like this after:
array = ['Katherine', 999.0, 333.0]
I have this list:
array = ['Katherine', '999', '333']
I need to convert the '999'
and '333'
into floats.
The list should look like this after:
array = ['Katherine', 999.0, 333.0]
Yeah, float(s)
can do this. Here is the code.
array = ['Katherine', '999', '333']
def is_number(s):
""" Returns True if the string is a number. """
try:
float(s)
return True
except ValueError:
return False
print(array)
// for i, v in enumerate(array):
// if is_number(v):
// array[i] = float(v)
array = list(map(is_number, array))
print(array)