a = ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]
def dirReduc(arr):
index = int(0)
for i in arr:
for j in arr:
if (len(arr[index]) == len(arr[index + 1])) and (arr[index] != arr[index + 1]):
arr.pop(index)
arr.pop(index)
index = 0
else:
index += 1
print(arr)
dirReduc(a)
The purpose of this code is to reduce opposite directions which are next to each other. While my pycharm giving me correct output without any errors which is:
arr = ["WEST"]
At codewars website where it should compile i'm passing all test but the site giving me:
IndexError: list index out of range
Any simple way to handle that error to make it work at codewars?