Skip to content

Instantly share code, notes, and snippets.

@ClaudiuCreanga
Created December 18, 2019 15:21
Show Gist options
  • Save ClaudiuCreanga/6f920badab36067cdb4e3b9a52355332 to your computer and use it in GitHub Desktop.
Save ClaudiuCreanga/6f920badab36067cdb4e3b9a52355332 to your computer and use it in GitHub Desktop.
array[~i] gets the equivalent from the end
so if i = 0, n[~i] is len(n) - 1 and so on.
def loopbothways(n):
i = 0
while i < len(n) // 2:
print(n[i])
print(n[~i])
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment