#This option produces a reversed copy of the list. Contrast this to mylist.reverse() which
#reverses the original list
>>> mylist
[1, 2, 3, 4, 5]
>>> mylist[::-1]
[5, 4, 3, 2, 1]
# To reverse a list use simply: reverse() method
# Example
list = [1, 2, 3]
list.reverse()
# Output
[3, 2, 1]
# to reverse any other type, we can use reversed()
# The reversed() function returns an iterator that accesses the given sequence in the reverse order.
# Example
list = [1, 2, 3]
list(reversed(list))
# Output
[3, 2, 1]
# reversed() returns an iterator so we can loop over it
# Example
for num in reversed(list):
print(num)
# Output
3
2
1
# Python code
#To reverse list
#input list
lst=[10, 11, 12, 13, 14, 15]
# the above input can also be given as
# lst=list(map(int,input().split()))
l=[] # empty list
# checking if elements present in the list or not
for i in lst:
#reversing the list
l.insert(0,i)
# printing result
print(l)
# Reversing a list using reversed()
def Reverse(lst):
return [ele for ele in reversed(lst)]
# Driver Code
lst = [10, 11, 12, 13, 14, 15]
print(Reverse(lst))
Function ReverseArray(arr As Variant) As Variant
Dim val As Variant
With CreateObject("System.Collections.ArrayList") '<-- create a "temporary" array list with late binding
For Each val In arr '<--| fill arraylist
.Add val
Next val
.Reverse '<--| reverse it
ReverseArray = .Toarray '<--| write it into an array
End With
End Function