-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
  • 2,154
  • 3
  • 16
  • 26

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
  • 3,168
  • 3
  • 18
  • 35
0

I would try:

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