def _flatten(l, max_level=10):
    """Generator function going deep in tree-like structures
    (i.e. dicts in dicts or lists in lists etc.) and returning all elements as
    a flat list. It's flattening only lists and dicts which are subclasses of
    RdyToFlattenCollection. Regular lists and dicts are treated as a
    single items.

    :param l: some iterable to be flattened
    :return: flattened iterator
    """
    if max_level >= 0:
        _iter = l.values() if isinstance(l, dict) else l
        for el in _iter:
            if isinstance(el, RdyToFlattenCollection):
                for sub in _flatten(el, max_level=max_level - 1):
                    yield sub
            else:
                yield el
    else:
        yield l
Generator function going deep in tree-like structures
    (i.e. dicts in dicts or lists in lists etc.) and returning all elements as
    a flat list. It's flattening only lists and dicts which are subclasses of
    RdyToFlattenCollection. Regular lists and dicts are treated as a
    single items.

    :param l: some iterable to be flattened
    :return: flattened iterator