Continually match values to a list of keys and values in Python
Question: I have a list of keys:

    
    
    Keys=['Description of Supplier:', 'Locally Produced:', 'Imported:', 'Female Managed:', 'Female Owned:', 'Closest Landmark:', '% National Staff:', '% International Staff:', 'Operating since:', 'Previous Name:']
    

I am looping over several web pages to retrieve the contents of the table as a
dictionary of values and keys:

    
    
    webpage1={'Description of Supplier:': 'Hardware, farm tools, articles for office and school supplies (Quincaillerie, outils agricoles, articles pour bureau et articles scolaires)', 'Female Owned:': 'NO', 'Operating since:': '01/1990', 'Female Managed:': 'NO', '% National Staff:': '100', 'Locally Produced:': '100%', 'Previous Name:': ''}
    
    webpage2={'Description of Supplier:': 'Produce, foods', 'Female Owned:': 'YES', 'Operating since:': '1987', 'Female Managed:': 'NO', '% National Staff:': '80', 'Locally Produced:': '100%', 'Previous Name:': 'Kshop'}
    

I want to combine the dictionaries by the keys:

    
    
    newdict={'Description of Supplier:': ['Hardware, farm tools, articles for office and school supplies (Quincaillerie, outils agricoles, articles pour bureau et articles scolaires)','Produce, foods'], 'Female Owned:': ['NO','YES'], 'Operating since:': ['01/1990','1987'], 'Female Managed:': ['NO','NO'], '% National Staff:': ['100','80'], 'Locally Produced:': ['100%','100%] , 'Previous Name:': ['','kshop']}
    

However the values have to be in the right order ( I am writing them to a csv
file).

I am stuck on how to do this in the most efficient way. Any suggestions?
Thanks so much in advance!


Answer: Using
[`collections.defaultdict`](http://docs.python.org/2/library/collections.html#collections.defaultdict):

    
    
    from collections import defaultdict
    
    newdict = defaultdict(list)
    for webpage in (webpage1, webpage2):
        for key, value in webpage1.items():
            newdict[key].append(value)
    
    newdict = dict(newdict)
    

* * *

`newdict`:

    
    
    {'% National Staff:': ['100', '80'],
     'Description of Supplier:': ['Hardware, farm tools, articles for office and school supplies (Quincaillerie, outils agricoles, articles pour bureau et articles scolaires)',
                                  'Produce, foods'],
     'Female Managed:': ['NO', 'NO'],
     'Female Owned:': ['NO', 'YES'],
     'Locally Produced:': ['100%', '100%'],
     'Operating since:': ['01/1990', '1987'],
     'Previous Name:': ['', 'Kshop']}
    

