【发布时间】:2020-11-12 13:40:06
【问题描述】:
我想从列表中的int 值中删除字符串字符。当我从下面的语句中删除str 字符时,它会扔给我TypeError:'int' object is not iterable。我怎样才能做到这一点?
for record in serializer.data:
if record:
less_eight = [x for x in str(record['car_cc'])]
print(less_eight)
else:
#some logic
输出:
['8', '0', '0']
['5', '0', '0']
我想要的是:
[8, 0, 0]
[5, 0, 0]
【问题讨论】:
-
[int(x) for x in str(record['car_cc'])]
标签: python django django-rest-framework