def ohm_to_spec_list(ohm, value_transform=lambda x: x):
    """Convert OrderedHierarchicalMapping to specification list

    The value_transform argument should be a function that transforms
    the values of the ohm to the entries of the spec list.
    """
    spec = []
    level_start = "["
    level_stop = "]"

    sorted_items = sort_ohm(ohm)

    def skip_to_header(spec, section_header):
        """Skips to the next header"""
        index = spec.index(section_header)
        for elem in spec[index:]:
            if not elem[0] == six.b('[')[0]:
                continue
            else:
                index += 1
        return index

    for key, value in sorted_items:
        split_key = key.split(ohm.SECTION_SEPARATOR)
        index = None
        if len(split_key) > 1:
            for level, part in zip(count_up(1), split_key[:-1]):
                section_header = (level * level_start +
                                  part +
                                  level*level_stop).encode()
                if spec in section_header:
                    index = skip_to_header(spec, section_header)
                    continue
                else:
                    spec += [section_header]
                    index = skip_to_header(spec, section_header)

        spec_entry = (split_key[-1] +
                      " = " +
                      value_transform(value))
        if index is None:
            spec += [spec_entry.encode()]
        else:
            spec.insert(index + 1, spec_entry.encode())
    return spec
dataset/ETHPy150Open duerrp/pyexperiment/pyexperiment/utils/config_conversion.py/ohm_to_spec_list/swapped operands of `in`