+ 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']??

2nd Apr 2018, 9:40 PM
Taylor Deal
Taylor Deal - avatar
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)
2nd Apr 2018, 9:53 PM
Tomer Sim
Tomer Sim - avatar
+ 1
How do i do this using append?
2nd Apr 2018, 11:29 PM
Taylor Deal
Taylor Deal - avatar