I trying to delete a certain elements from a list when two elements are "together" in a specific order expressed in the if statements. However, if the conditions are met, they both do the same thing, so I was wondering if there is a way to not write the same code to execute in each statement, and only do it when an if statement is met.
arr = ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]
if arr[i] == "SOUTH" and arr[j] == "NORTH":
del arr[i]
del arr[j]
length-=2
if arr[i] == "NORTH" and arr[j] == "SOUTH":
del arr[i]
del arr[j]
length-=2
if arr[i] == "WEST" and arr[j] == "EAST":
del arr[i]
del arr[j]
if arr[i] == "EAST" and arr[j] == "WEST":
del arr[i]
del arr[j]
length-=2