how to convert floats into ints in the mixed list with words, NaNs and floats? i have tried all the described ways, no one of them works
how to convert floats into ints in the mixed list with words, NaNs and floats? i have tried all the described ways, no one of them works.
Ответы (1 шт):
Автор решения: nomnoms12
→ Ссылка
Можно проверять тип с помощью условия if type(x) == float.
Пример:
li = [True, 3.14159265, '177.013', 12, 11.7, 'word', None, False]
for i in range(len(li)):
x = li[i]
if type(x) == float:
li[i] = int(x)
print(li)
stdout:
[True, 3, '177.013', 12, 11, 'word', None, False]