def _flatten(d, parent_key='', sep='.'):
    """flattens a dictionary into a list of (k, v) tuples."""
    items = []
    for k, v in d.items():
        k_ = '{}{}{}'.format(parent_key, sep, k) if parent_key else k
        if isinstance(v, dict):
            items.extend(_flatten(v, k_, sep=sep))
        else:
            items.append((k_, v))
    return items