我是蟒蛇的新手。我一直在尝试计算 1-9 在列表中出现的次数,但 python 不会计算该数字并始终将其视为 1,而不会为数字 1-9 的出现次数添加更多计数。有谁可以帮助我理解为什么?
#code
for nmb in ls:
if nmb is not ls:
frstdic[nmb] = 1
else:
frstdic[nmb] = frstdic[nmb] + 1
print (frstdic)
#return
{'1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1}
# nmb is a string
慕哥9229398
相关分类