0

Moving elements in a list

I need to move the last three elements from the end of a list to the start in the same order. Is this code correct? y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y[:0] = y[-3:] del y[-3:] Can I do it with a single line of code? Sorry for my bad english...

12th Feb 2020, 11:47 AM
Max Ba
Max Ba - avatar
4 Respostas
+ 3
print(y[-3:]+y[:-3])
12th Feb 2020, 11:57 AM
Mihai Apostol
Mihai Apostol - avatar
12th Feb 2020, 11:53 AM
Gordon
Gordon - avatar
+ 1
Thank you
12th Feb 2020, 12:02 PM
Max Ba
Max Ba - avatar
+ 1
You're welcome.
12th Feb 2020, 12:04 PM
Mihai Apostol
Mihai Apostol - avatar