Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Last active December 5, 2019 01:49
Show Gist options
  • Save FerdinaKusumah/7dc6550268e4acbefe5f94837848f206 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/7dc6550268e4acbefe5f94837848f206 to your computer and use it in GitHub Desktop.
Reverse List
"""Reverse list"""
a = [1, 2, 3, 4, 5]
reversed_list = a[::-1]
print("Reverse from {} to {}".format(a, reversed_list))
# Reverse from [1, 2, 3, 4, 5] to [5, 4, 3, 2, 1]
"""Iterate over reversed list efficiency"""
for num in reversed(a):
print(num)
# 5
# 4
# 3
# 2
# 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment