def tree_item_iterator(items):
    structure = {}
    first_level = False
    for previous, current, next in previous_current_next(items):
        
        current_level = getattr(current, 'depth')

        if previous:
            structure['new_level'] = (getattr(previous,
                                              'depth') < current_level)
        else:
            first_level = current_level
            structure['new_level'] = True

        if next:
            structure['closed_levels'] = range(current_level,
                                               getattr(next,
                                                       'depth'), -1)
        else:
            # All remaining levels need to be closed
            structure['closed_levels'] = range(current_level - first_level, -1, -1)

        # Return a deep copy of the structure dict so this function can
        # be used in situations where the iterator is consumed
        # immediately.
        yield current, copy.deepcopy(structure)
Given a list of tree items, iterates over the list, generating
dataset/ETHPy150Open fabiocorneti/django-easytree/easytree/templatetags/easytree_tags.py/tree_item_iterator