def flatten(d):
    """Recursively flatten dictionary values in `d`.
    >>> hat = {'cat': ['images/cat-in-the-hat.png'],
    ...        'fish': {'colours': {'red': [0xFF0000], 'blue': [0x0000FF]},
    ...                 'numbers': {'one': [1], 'two': [2]}},
    ...        'food': {'eggs': {'green': [0x00FF00]},
    ...                 'ham': ['lean', 'medium', 'fat']}}
    >>> set_of_values = set(flatten(hat))
    >>> sorted(set_of_values)
    [1, 2, 255, 65280, 16711680, 'fat', 'images/cat-in-the-hat.png', 'lean', 'medium']
    """
try:
    for v in d.values():
        for nested_v in flatten(v):
            yield nested_v
except AttributeError:
    for list_v in d:
        yield list_v
Flatten a dictionary of dictionaries (2 levels deep) of lists in Python