+ 1
reverse list and add it to end of original list
This is the code I have so far to reverse list l and try to add it onto the original: def mirror(l): a = l.reverse() print(l + a) But it doesn't work, how to I get a list such as ['a', 'b', 'c'] to output ['a', 'b', 'c', 'c', 'b', 'a']??
2 Réponses
+ 2
It doesn't work because of this.
array.reverse() doesn't copy the elements of the array backwards to an other array.
it reverses the array you called it on. (array is now reversed)
so you should do this.
def mirror(arr):
z=[]
z+=arr
arr.reverse()
z+=arr
print(z)
+ 1
How do i do this using append?