def clean_data(data: List[list]) -> None:
"""Convert each string in data to an int if and only if it represents a
whole number, a float if and only if it represents a number that is not a
whole number, True if and only if it is 'True', False if and only if it is
'False', and None if and only if it is either 'null' or the empty string.
>>> d = [['abc', '123', '45.6', 'True', 'False']]
>>> clean_data(d)
>>> d
[['abc', 123, 45.6, True, False]]
>>> d = [['ab2'], ['-123'], ['False', '3.2']]
>>> clean_data(d)
>>> d
[['ab2'], [-123], [False, 3.2]]
"""
d = []
for sublist in data:
l1 = []
if i.isalpha():
l1.append(i)
elif i.isdigit():
l1.append(int(i))
Tags:
如果不想使用任何软件包,请尝试以下操作:
其输出如下:
尽管less advisable,另一种可能的方法是使用内置的
eval()
函数:其输出相同。你知道吗
相关问题 更多 >
编程相关推荐