+ 1

[1,2,3,4,5]->[5,4,3,2,1](we have to reverse the digits )

can anyone try better than me? a=[1,2,3,4,5] for i in range(len(a)//2): temp=a[0+i] a[0+i]=a[-1-i] a[-1-i]=temp print(a)

18th Dec 2020, 6:01 PM
Prabhas
4 Respuestas
+ 2
Thanks
18th Dec 2020, 6:10 PM
Prabhas
+ 1
lst=[1, 2, 3, 4, 5] print(lst[::-1] It's simple. And one liner
20th Dec 2020, 3:01 PM
‎Keshav
‎Keshav - avatar
0
print(reversed(a))
19th Dec 2020, 7:38 PM
Arman