In line 52 of my code I keep getting the error, fact_check.py:52: [C0206(consider-using-dict-items), get_totals] Consider iterating with .items()
and I don't know how to fix it. the section of code is as follows...
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
Haven't tried much because honestly I don't know why its doing this. Any information helps.
That's not an error, and it was not issued by Python. You can replace those first two statements with
for i,k in pre_output.items():
and get both at once.-- Comment by Tim Roberts