def remove_circular_paths(path):
    'Removes pieces of the path that just end on the same node'
    edge_pattern = re.compile('edge_(?P<begin_node>\\w+)_(?P<end_node>\\w+)_(?P<iterator>\\w+)')
    past_locations = []
    for (index, edge) in enumerate(path):
        match = re.match(edge_pattern, edge)
        begin_node = match.groupdict()['begin_node']
        end_node = match.groupdict()['end_node']
        past_locations.append(begin_node)
    new_path = []
    node_index = 0
    between_list = [False for item in past_locations]
    while (node_index < len(past_locations)):
        node = past_locations[node_index]
        old_path = new_path
        new_path = []
        number_of_visits = past_locations.count(node)
        if (number_of_visits > 1):
            equality_list = [(x == node) for x in past_locations]
            print('{0} is {1}'.format('equality_list', equality_list))
            between = False
            visit_number = 0
            for (index, equality) in enumerate(equality_list):
                if equality:
                    visit_number += 1
                    if ((visit_number == 1) or (visit_number == number_of_visits)):
                        between = (not between)
                        between_list[index] = (between or between_list[index])
                    else:
                        between_list[index] = (between or between_list[index])
                else:
                    between_list[index] = (between or between_list[index])
        for (index, item) in enumerate(between_list):
            if (not item):
                new_path.append(path[index])
        node_index += 1
    if (new_path in [[]]):
        new_path = path
    return new_path
Removes pieces of the path that just end on the same node
def remove_circular_paths(path):
    
    edge_pattern = re.compile('edge_(?P<begin_node>\\w+)_(?P<end_node>\\w+)_(?P<iterator>\\w+)')
    past_locations = []
    for (index, edge) in enumerate(path):
        match = re.match(edge_pattern, edge)
        begin_node = match.groupdict()['begin_node']
        end_node = match.groupdict()['end_node']
        past_locations.append(begin_node)
    new_path = []
    node_index = 0
    between_list = [False for item in past_locations]
    while (node_index < len(past_locations)):
        node = past_locations[node_index]
        old_path = new_path
        new_path = []
        number_of_visits = past_locations.count(node)
        if (number_of_visits > 1):
            equality_list = [(x == node) for x in past_locations]
            print('{0} is {1}'.format('equality_list', equality_list))
            between = False
            visit_number = 0
            for (index, equality) in enumerate(equality_list):
                if equality:
                    visit_number += 1
                    if ((visit_number == 1) or (visit_number == number_of_visits)):
                        between = (not between)
                        between_list[index] = (between or between_list[index])
                    else:
                        between_list[index] = (between or between_list[index])
                else:
                    between_list[index] = (between or between_list[index])
        for (index, item) in enumerate(between_list):
            if (not item):
                new_path.append(path[index])
        node_index += 1
    if (new_path in [[]]):
        new_path = path
    return new_path