Dictionary with multiple string values for a key

dictionary, python

Solution

You can use a `collections.defaultdict`:

>>> from collections import defaultdict
>>>
>>> d = defaultdict(list)
>>> d['key'].append(5)
>>> d
defaultdict(<type 'list'>, {'key': [5]})
>>> dict(d)
{'key': [5]}

Problem

I need a dictionary that is composed by a lot of keys, and the values must be a list that contains lots of strings. (in Python) I tried: ``` d1[key].append(value) ``` but Python says: ``` AttributeError: 'str' object has no attribute 'append'. ``` I need something like : `{a:[b,c,d,e],b:[t,r,s,z]....}` What could I do? thanks in advance.

Original source