Python Function returns wrong value
Question: 
    periodsList = [] 
    su = '0:'
    Su = []
    sun = []
    SUN = ''
    

I'm formating timetables by converting

    
    
    extendedPeriods = ['0: 1200 - 1500',
        '0: 1800 - 2330',
        '2: 1200 - 1500',
        '2: 1800 - 2330',
        '3: 1200 - 1500',
        '3: 1800 - 2330',
        '4: 1200 - 1500',
        '4: 1800 - 2330',
        '5: 1200 - 1500',
        '5: 1800 - 2330',
        '6: 1200 - 1500',
        '6: 1800 - 2330']
    

into `'1200 - 1500/1800 - 2330'`

  * su is the day identifier
  * Su, sun store some values
  * SUN stores the converted timetable 
    
        for line in  extendedPeriods:
      if su in line:    
        Su.append(line)
    
      for item in Su:
        sun.append(item.replace(su, '', 1).strip())
    
      SUN = '/'.join([str(x) for x in sun])
    

Then I tried to write a function to apply my "converter" also to the other
days..

    
    
    def formatPeriods(id, store1, store2, periodsDay): 
      for line in extendedPeriods:
        if id in line:    
          store1.append(line)
    
      for item in store1:
        store2.append(item.replace(id, '', 1).strip())
    
      periodsDay = '/'.join([str(x) for x in store2])  
      return periodsDay     
    

But the function returns 12 misformatted strings...

    
    
    '1200 - 1500', '1200 - 1500/1200 - 1500/1800 - 2330',
    


Answer: You can use `collections.OrderedDict` here, if order doesn't matter then use
`collections.defaultdict`

    
    
    >>> from collections import OrderedDict
    >>> dic = OrderedDict()
    for item in extendedPeriods:
        k,v = item.split(': ')
        dic.setdefault(k,[]).append(v)
    ...     
    >>> for k,v in dic.iteritems():
    ...     print "/".join(v)
    ...     
    1200 - 1500/1800 - 2330
    1200 - 1500/1800 - 2330
    1200 - 1500/1800 - 2330
    1200 - 1500/1800 - 2330
    1200 - 1500/1800 - 2330
    1200 - 1500/1800 - 2330
    

To access a particular day you can use:

    
    
    >>> print "/".join(dic['0'])   #sunday
    1200 - 1500/1800 - 2330
    >>> print "/".join(dic['2'])   #tuesday
    1200 - 1500/1800 - 2330
    

