Last active
December 5, 2019 01:49
-
-
Save FerdinaKusumah/7dc6550268e4acbefe5f94837848f206 to your computer and use it in GitHub Desktop.
Reverse List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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