Write a programExercise 4/4Intermediate30 XP

Shifting by k places

Task

Write a function posun(zoznam, k) that returns a new list with the items shifted k places to the right. Items that "fall off" the end move to the start:

  • posun([1, 2, 3, 4], 1) returns [4, 1, 2, 3],
  • posun([1, 2, 3, 4], 6) returns [3, 4, 1, 2] - k may be larger than the length of the list.

The original list must not change, and it may also be empty.

Examples

  • Call

    print(posun([1, 2, 3, 4], 1))

    Expected output

    [4, 1, 2, 3]
  • Call

    print(posun([1, 2, 3, 4], 2))

    Expected output

    [3, 4, 1, 2]

After you submit, 5 hidden tests will also check your solution: a shift by 0, a shift by the whole length, k larger than the length, an empty list, the original list stays the same.

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.