Function in Python that Reverse a given List
The following function in python will return the reverse of the given list.
def reverseList(n):
reverseL = uList[:]
for i in range(len(reverseL)//2):
reverseL[i], reverseL[len(reverseL)-i-1] = reverseL[len(reverseL)-i-1], reverseL[i]
print(f"The reverse of the original list {uList} is {reverseL}")
uList = [45,66,7,1,333]
reverseList(uList)
Comments
Post a Comment
Write something to CodeWithAbdur!