How to add iteration values in dictionary?
I want to make the dictionary, (key: days, value: occurence) in a textfile First, I have to extract lines which starts with 'From' and after split the line, In the line, extract the second word which is 'days' like monday, tuesday... And finally. Add the days as the key and occurences as the value in dictionary The expected result is.. {'Fri':20, 'Thu':6, 'Sat':1} I wrote as follow: file=open('mbox-short.txt') counts=dict() for line in file: line=line.rstrip() If line.startswith('From:'):continue If line.starswith('From'): words=line.split() days=words[2] for day in days: counts[day]=counts.get(day,0)+1 else: continue Print counts Is there anyone who can solve this problem? Help me out please-