Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created June 19, 2019 03:33
Show Gist options
  • Save Shaddyjr/8e9937d41d4f0b58ccfaa63ab9810efd to your computer and use it in GitHub Desktop.
Save Shaddyjr/8e9937d41d4f0b58ccfaa63ab9810efd to your computer and use it in GitHub Desktop.
# All credit to the following users on Code Wars:
# aenik97, CSNqwer, kickh, joei26, suhlob
opposite = {'NORTH': 'SOUTH', 'EAST': 'WEST', 'SOUTH': 'NORTH', 'WEST': 'EAST'}
def dirReduc(plan):
new_plan = []
for d in plan:
if new_plan and new_plan[-1] == opposite[d]:
new_plan.pop()
else:
new_plan.append(d)
return new_plan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment