I'm trying to solve a project where i have to count the years in a list but I`m having problems understanding the difference between
years = [n[1] for n in data]
and
for n in data:
years = n[1]
here is the rest of the body
for m in years:
if m not in year_counts:
year_counts[m] = 0
year_counts[m] += 1
print(year_counts)
So if I use the first sentence then the code will run normally and will show the proper answer but if i use the second code it will give me random numbers I don't know from where.
yearslook like?