【发布时间】:2021-08-01 13:07:15
【问题描述】:
该值存在于列表中。
list = ['4', '4', '4', '1,119', '1,119', '1,119']
我尝试将 Nonetype 转换为 int。
list = ['4', '4', '4', '1,119', '1,119', '1,119']
for i in list :
a = [int(x.replace(',', '')) for x in list]
print(set(list))
TypeError: 'NoneType' object is not iterable
我想要输出
list = [4,1119]
【问题讨论】:
-
int(i.replace(",","")) -
不要命名你自己的变量
list,因为你覆盖了内置函数[list}(docs.python.org/3/library/functions.html#func-list)。
标签: python