There are some data type is float, for example
24.0, 34.0, 35.6, 33.2, 44.0
I want
24.0, 34.0, 44.0
change into
24,34,44.
35.6
and 33.2
do not change.
how could I do that?
There are some data type is float, for example
24.0, 34.0, 35.6, 33.2, 44.0
I want
24.0, 34.0, 44.0
change into
24,34,44.
35.6
and 33.2
do not change.
how could I do that?
Let me put that data types into a list,
list_num = [24.0, 34.0, 35.6, 33.2, 44.0]
newList=[int(i) if int(i)== i else i for i in list_num]
print newList
Since 44.0 == 44 #True
you can do the following:
li = [24.0, 34.0, 35.6, 33.2, 44.0]
print map(lambda x: int(x) if int(x) == x else x, li)
>> [24, 34, 35.6, 33.2, 44]
using string formatting:
>>> l = [24.0, 34.0, 35.6, 33.2, 44.0]
>>> ['{0:g}'.format(x) for x in l]
['24', '34', '35.6', '33.2', '44']