<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def flatten_dict(self, d, delimiter="-", intermediates=False, parent_key=None):
 """ Flatten a dictionary. Values that are dictionaries are flattened using delimiter in between (eg. parent-child) Values that are lists are flattened using delimiter followed by the index (eg. parent-0) example: .. code-block:: python { 'fish_facts': { 'sharks': 'Most will drown if they stop moving', 'skates': 'More than 200 species', }, 'fruits': ['apple', 'peach', 'watermelon'], 'number': 52 } # becomes { 'fish_facts-sharks': 'Most will drown if they stop moving', 'fish_facts-skates': 'More than 200 species', 'fruits-0': 'apple', 'fruits-1': 'peach', 'fruits-2': 'watermelon', 'number': 52 } # if intermediates is True then we also get unflattened elements # as well as the flattened ones. { 'fish_facts': { 'sharks': 'Most will drown if they stop moving', 'skates': 'More than 200 species', }, 'fish_facts-sharks': 'Most will drown if they stop moving', 'fish_facts-skates': 'More than 200 species', 'fruits': ['apple', 'peach', 'watermelon'], 'fruits-0': 'apple', 'fruits-1': 'peach', 'fruits-2': 'watermelon', 'number': 52 } """

        items = []
        if isinstance(d, list):
            d = dict(enumerate(d))
        for k, v in d.items():
            if parent_key:
                k = u"{}{}{}".format(parent_key, delimiter, k)
            if intermediates:
                items.append((k, v))
            if isinstance(v, list):
                v = dict(enumerate(v))
            if isinstance(v, collections.Mapping):
                items.extend(
                    self.flatten_dict(v, delimiter, intermediates, str(k)).items()
                )
            else:
                items.append((str(k), v))
        return dict(items)