-1

I am trying to create a function that reverses and mutates a list via slicing/appending without using [::-1] or .reverse(). I am looking for any additional resources online but it seems to be the only two popular reserving techniques.
Can anyone help me think of how I can write this?

skaul05
  • 1,994
  • 2
  • 15
  • 24

2 Answers2

0

This is one way you can do it:

a = [1, 2, 3, 4]
b = [0]*len(a)

for i in range(len(a)):
    b[len(a) - 1 - i] = a[i]
print(b)
learner
  • 2,608
  • 1
  • 14
  • 29
0

I would try:

n = len(a)
for i in range(n):
    a.append(a[n - (i+1)])
a = a[n:]
NG_
  • 125
  • 3
  • 8