# Story
John found a path to a treasure, and while searching for its precise location he wrote a list of directions using symbols `"^"`, `"v"`, `"<"`, `">"` which mean `north`, `east`, `west`, and `east` accordingly. On his way John had to try many different paths, sometimes walking in circles, and even missing the treasure completely before finally noticing it.
___
## Task
Simplify the list of directions written by John by eliminating any loops.
**Note**: a loop is any sublist of directions which leads John to the coordinate he had already visited.
___
## Examples
```
simplify("<>>")        ==  ">"
simplify("<^^>v<^^^")  ==  "<^^^^"
simplify("")           ==  ""
simplify("^< > v
    ^   v
> > C > D > >
^   ^   v
^ < B < <
    ^
    A
```
John visits points `A -> B -> C -> D -> B -> C -> D`, realizes that `-> C -> D -> B` steps are meaningless and removes them, getting this path: `A -> B -> (*removed*) -> C -> D`.
```
    ∙ ∙ ∙
    ∙   ∙
> > C > D > >
^   ∙   ∙
^ < B ∙ ∙
    ^
    A
```
Following the final, simplified route John visits points `C` and `D`, but for the first time, not the second (because we ignore the steps made on a hypothetical path), and he doesn't need to alter the directions list anymore.
def simplify(path):
    location = (0,0)
    new_path = path
    new_path_locations = [location]
    
    for d in path:
        if d == '<': location = (location[0]-1, location[1])
        elif d == '>': location = (location[0]+1, location[1])
        elif d == 'v': location = (location[0], location[1]+1)
        else: location = (location[0], location[1]-1)
        
        if location in new_path_locations:
            i = new_path_locations.index(location)
            
            remove_length = len(new_path_locations) - i
            
            new_path_locations = new_path_locations[:i+1] # leave the current location
            
            new_path = new_path[:i] + new_path[i+remove_length:]
        
        else: new_path_locations.append(location)
    
    return new_path
def simplify(path):
    location = (0,0)
    new_path = path
    new_path_locations = [location]
    
    for d in path:
        if d == '<': location = (location[0]-1, location[1])
        elif d == '>': location = (location[0]+1, location[1])
        elif d == 'v': location = (location[0], location[1]+1)
        else: location = (location[0], location[1]-1)
        
        if location in new_path_locations:
            i = new_path_locations.index(location)
            
            remove_length = len(new_path_locations) - i
            
            new_path_locations = new_path_locations[:i+1] # leave the current location
            
            new_path = new_path[:i] + new_path[i+remove_length:]
        
        else: new_path_locations.append(location)
    
    return new_path