def nested_dict_to_list_of_tuples(d, separator='.', extra_nesting=False):
    """ Take a 2-level nested dict of dict to list of tuples.
        to preserve some structure, the keys from the two levels are 
        joined with the separator string.
        If extra_nesting is true, the inner items are wrapped in an extra
        tuple. 
        This function is mainly to support use with my black box tuning code,
        which represents the search space as key-tuple(value) pairs."""
    l = []
    for outer_key, outer_value in d.items():
        assert separator not in outer_key, 'Please try another separator!'
        for inner_key, inner_value in outer_value.items():
            assert separator not in inner_key, 'Please try another separator!'
            if extra_nesting:
                inner_value = [inner_value]
            l.append((outer_key + separator + inner_key, inner_value))
    return l