py_twist_sequence

Código comentado línea a línea y paso a paso:

Entregas: py_twist_sequence.py con twist_sequence(arr, k). Rank 03 · nivel 5.

Qué pide (en palabras normales)

Subject (enunciado original)
Write a function that rotates an array to the right by k positions.
Rotating right by k means the last k elements move to the front.

Expected file: py_twist_sequence.py
Function signature:
def twist_sequence(arr: list[int], k: int) -> list[int]:

Examples:
twist_sequence([1,2,3,4,5], 2)
=> [4,5,1,2,3]
twist_sequence([1,2,3], 1)
=> [3,1,2]
twist_sequence([1,2,3,4], 0)
=> [1,2,3,4]
twist_sequence([1,2,3], 5)
=> [2,3,1]
twist_sequence([], 3)
=> []

Solución: slices

if not arr:
    return []
k %= len(arr)
return arr[-k:] + arr[:-k] if k else list(arr)

Dos slices y una suma. Todo el ejercicio está en los casos límite.

Trampas