python print list backwards code example
Example 1: how to flip a list backwards in python
myList = [0,1,2,3,4,5]
myList.reverse()
print(myList)
print(myList[::-1])
Example 2: print list in reverse order python
languages = ['C++', 'Python', 'Scratch']
languages.reverse()
print(languages)
lang = languages[::-1]
print(lang)
Example 3: python iterate backwards through list
>>> a = ["foo", "bar", "baz"]
>>> for i in reversed(a):
... print(i)
...
or
>>> for i, e in reversed(list(enumerate(a))):
... print(i, e)
Example 4: python reverse list
systems = ['Windows', 'macOS', 'Linux']
print('Original List:', systems)
reversed_list = systems[::-1]
print('Updated List:', reversed_list)
Example 5: iterate backwards through a list python
a = ["foo","bar","baz"]
for i in range(len(a)-1,-1,-1):
print(a[i])
Example 6: python get reversed list
list.reverse()