Extract the year and the month from a line in a file and use a map to print every time its found to add 1 to the value
Question: 
    def Stats():
        file = open('mbox.txt')
        d = dict()
        for line in file:
            if line.startswith('From'):
                words = line.split()
                for words in file:
                    key = words[3] + " " + words[6]
                    if key:
                        d[key] +=1
        return d
    

The line reads

    
    
    From stephen.marquard@uct.ac.za Sat Jan  5 09:14:16 2008
    

I want to pull "Jan 2008" as the key

My error message:

    
    
    Traceback (most recent call last):
      File "C:\Users\Robert\Documents\PYTHON WORKSPACE\Program 1.py", line 78, in <module>
      File "C:\Users\Robert\Documents\PYTHON WORKSPACE\Program 1.py", line 76, in <module>
      File "C:\Users\Robert\Documents\PYTHON WORKSPACE\Program 1.py", line 63, in <module>
    builtins.KeyError: 'u -'
    


Answer: Not the direct answer to the question, but a possible alternative solution -
use the [`dateutil`](https://labix.org/python-dateutil) datetime parser in a
"fuzzy" mode and simply format the extracted `datetime` object via
[`.strftime()`](https://docs.python.org/2/library/datetime.html#datetime.datetime.strftime):

    
    
    In [1]: from dateutil.parser import parse
    
    In [2]: s = "From stephen.marquard@uct.ac.za Sat Jan  5 09:14:16 2008"
    
    In [3]: parse(s, fuzzy=True).strftime("%b %Y")
    Out[3]: 'Jan 2008'
    

