为什么我得到这个错误,它是可修复的吗?C0206 (consider-using-dict-items)



在我的代码的第52行,我一直得到错误,fact_check.py:52: [C0206(consider-using-dict-items), get_totals] Consider iterating with .items()和我不知道如何修复它。这段代码如下…

def get_totals(data, presidents):
'''
Description: Takes a list of raw data, and a dictionary of years adn the associated president.
It then creates an output list, with the total jobs and their associated president
Requires: List data, Dictionary presidents
Returns: List output
'''
output = []
pre_output = {}
for i in data:
i[0] = int(i[0])
try:
pre_output[presidents[i[0] - 1]].append(i[1])
pre_output[presidents[i[0]]].extend(i[1: ])
except KeyError:
pre_output[presidents[i[0]]] = []
pre_output[presidents[i[0]]].extend(i[1: ])
for i in pre_output:  # <---- (line 52)
k = pre_output[i]
tmp_list = [i]
before = int(k[0])
total = 0
j = _
for j in k:
if j == '':
continue
j = int(j)
total += j - before
before = j
tmp_list.append(total)
output.append(tmp_list)
return output

没有尝试过,因为老实说,我不知道为什么它这样做。任何信息都有帮助。

这不是一个错误,它不是由Python发出的。您可以将前两个语句替换为for i,k in pre_output.items():,并一次获得两个语句。

——评论by Tim Roberts

相关内容

  • 没有找到相关文章

最新更新