# What is the idiomatic way to shift and extend a list by a number of elements?

I have a lists, list, and want shift it right by a given number of elements, m, extending the list by repeating the last element. A form that works is

Drop[#, m]& @ PadRight[#, Length[#] + m, Last[#]]& @ list


which, for

m = 3
list = {3, 0, 7, 2, 1}


gives

{2, 1, 1, 1, 1}


and for

m = 2
list = {3, 8, 2, 7, 1, 6}


gives

{2, 7, 1, 6, 6, 6}


This is what I want, but I wonder if there is a more idiomatic way to accomplish it.

• Perhaps the accepted terminology is different among Mathematica users, but don't you mean you're shifting the list to the left? – David Zhang Jul 6 '15 at 20:46
• @DavidZhang: Yes, indeed! – orome Jul 6 '15 at 20:47

m = 2;

Join[list[[m + 1 ;;]], Table[list[[-1]], {m}]]