python list to dictionary with dates as keys
Question: I'm trying to create a dictionary from this list using dates as keys and
successive items as its value.

    
    
    lst = ['Thu Apr 04', ' Weigh In', 'Sat Apr 06', ' Collect NIC', ' Finish PTI Video', 'Wed Apr 10', ' Serum uric acid test', 'Sat Apr 13', ' 1:00pm', 'Get flag from dhariwal', 'Sun Apr 14', ' Louis CK Oh My God', ' 4:00pm', 'UPS Guy']
    
    dict = {}
    
    for item in lst:
        if item.startswith(('Mon','Tue','____Wed','Thu','Fri','Sat','Sun'__))__:
            dict[item] = []
            saveItem = item
        else:
            dict[saveItem].append(item.____strip())
    

Keeps giving me syntax error.

P.S. not my code


Answer: 
    import itertools as IT
    
    items = ['Thu Apr 04', ' Weigh In', 'Sat Apr 06', ' Collect NIC', ' Finish PTI Video', 'Wed Apr 10', ' Serum uric acid test', 'Sat Apr 13', ' 1:00pm', 'Get flag from dhariwal', 'Sun Apr 14', ' Louis CK Oh My God', ' 4:00pm', 'UPS Guy']
    
    date_word = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
    
    def isdate(datestring):
        return any(datestring.startswith(d) for d in date_word)
    
    items = (item.strip() for item in items)
    
    data = (list(group) for key, group in IT.groupby(items, key=isdate))
    for date, items in IT.izip(*[data]*2):
        print('{d} {i}'.format(d=date[0], i=items))
    

yields

    
    
    Thu Apr 04 ['Weigh In']
    Sat Apr 06 ['Collect NIC', 'Finish PTI Video']
    Wed Apr 10 ['Serum uric acid test']
    Sat Apr 13 ['1:00pm', 'Get flag from dhariwal']
    Sun Apr 14 ['Louis CK Oh My God', '4:00pm', 'UPS Guy']
    

* * *

  * You could use [IT.groupby](http://docs.python.org/2/library/itertools.html#itertools.groupby) to group the items as desired.

  * If you don't don't dump the items into a dict, you can preserve the order in which the items appear.

  * You can use the `zip(*[iterator]*2)` [grouper recipe](http://docs.python.org/2/library/itertools.html#itertools.izip) to group items in pairs.

  * Avoid using variable names like `dict` since they shadow the Python builtin object of the same name.

