def flatten_dict(dict_, parent_key='', sep='.'):
    'Flattens a nested dictionary. Namedtuples within the dictionary are\n    converted to dicts.\n\n    Adapted from:\n    https://github.com/google/seq2seq/blob/master/seq2seq/models/model_base.py\n\n    Args:\n        dict_ (dict): The dictionary to flatten.\n        parent_key (str): A prefix to prepend to each key.\n        sep (str): Separator that intervenes between parent and child keys.\n            E.g., if `sep` == \'.\', then `{ "a": { "b": 3 } }` is converted\n            into `{ "a.b": 3 }`.\n\n    Returns:\n        A new flattened `dict`.\n    '
    items = []
    for (key, value) in dict_.items():
        key_ = (((parent_key + sep) + key) if parent_key else key)
        if isinstance(value, collections.MutableMapping):
            items.extend(flatten_dict(value, key_, sep=sep).items())
        elif (isinstance(value, tuple) and hasattr(value, '_asdict')):
            dict_items = collections.OrderedDict(zip(value._fields, value))
            items.extend(flatten_dict(dict_items, key_, sep=sep).items())
        else:
            items.append((key_, value))
    return dict(items)
Flattens a nested dictionary. Namedtuples within the dictionary are
converted to dicts.

Adapted from:
https://github.com/google/seq2seq/blob/master/seq2seq/models/model_base.py

Args:
    dict_ (dict): The dictionary to flatten.
    parent_key (str): A prefix to prepend to each key.
    sep (str): Separator that intervenes between parent and child keys.
        E.g., if `sep` == '.', then `{ "a": { "b": 3 } }` is converted
        into `{ "a.b": 3 }`.

Returns:
    A new flattened `dict`.
def flatten_dict(dict_, parent_key=, sep='.'):
    'Flattens a nested dictionary. Namedtuples within the dictionary are\n    converted to dicts.\n\n    Adapted from:\n    https://github.com/google/seq2seq/blob/master/seq2seq/models/model_base.py\n\n    Args:\n        dict_ (dict): The dictionary to flatten.\n        parent_key (str): A prefix to prepend to each key.\n        sep (str): Separator that intervenes between parent and child keys.\n            E.g., if `sep` == \'.\', then `{ "a": { "b": 3 } }` is converted\n            into `{ "a.b": 3 }`.\n\n    Returns:\n        A new flattened `dict`.\n    '
    items = []
    for (key, value) in dict_.items():
        key_ = (((parent_key + sep) + key) if parent_key else key)
        if isinstance(value, collections.MutableMapping):
            items.extend(flatten_dict(value, key_, sep=sep).items())
        elif (isinstance(value, tuple) and hasattr(value, '_asdict')):
            dict_items = collections.OrderedDict(zip(value._fields, value))
            items.extend(flatten_dict(dict_items, key_, sep=sep).items())
        else:
            items.append((key_, value))
    return dict(items)