def convert_gravity_value(value):
"""Convert a planet's "gravity" value to a float. Removes the "standard" unit of measure if
it exists in the string. Delegates to the function < convert_to_float > the task of casting
the < value > to a float.
Parameters:
value (obj): string to be converted
Returns:
float: if value successfully converted; otherwise returns value unchanged
"""
try:
for this in value:
if this['standard']:
value.remove(this['standard'])
return convert_to_float(value)
except:
return value
// Where covert_to_float is just "return float(value)"
I have the following list: ['1 standard', '2 standard', '2.5', '3 standard', '3.56']
And I'm trying to write a function that takes in the list as a parameter so that it returns 1.0, 2.0, 2.5, 3.0, 3.56. If the 'standard' unit exists, it should be removed; else, the element should be directly converted to a float.