Reverse a list without built-in functions
How to reverse a list in Python without using built-in functions?
You can solve reverse a list in python without reverse function error in 2 ways:
Using user-defined-functions
Using [::-1] operator
Using user-defined-functions:
EXAMPLE:
def myfunc(a):
rev_str = []
for x in a:
rev_str.insert(0, x)
return rev_str
print(myfunc([1,2,3,4,5]))
OUTPUT:
[5, 4, 3, 2, 1]
Using [::-1]:
EXAMPLE:
y=[1,2,3,4,5]
z=y[::-1]
print(z)
OUTPUT:
[5, 4, 3, 2, 1]