Initialise or append dictionary list in python
Question: Can the following code snippet be simplified into one statement somehow?

    
    
    if aKey not in aDict:
        aDict[aKey] = [someValue]
    else: 
        aDict[aKey].append(someValue)
    

I could write a function accepting the `aDict`, `aKey` and `someValue`, but is
there a way to do this using only native python stuff?


Answer: [`collections.defaultdict`](https://docs.python.org/2/library/collections.html#collections.defaultdict)
is made just with this purpose in mind:

    
    
    In [1]: import collections
    
    In [2]: d = collections.defaultdict(list)
    
    In [3]: d['key'].append(1)
    
    In [4]: d
    Out[4]: defaultdict(<type 'list'>, {'key': [1]})
    
    In [5]: d['key'].append(2)
    
    In [6]: d
    Out[6]: defaultdict(<type 'list'>, {'key': [1, 2]})
    

Here, when you access a key that does not exist, it is automatically
initialised with an empty list.

