Python: How to shift values in a list

To shift values in a list (replace the value at the first place of the list to its last place and vice versa), you need to rearrange the list with two slices.

The shift for the list:

forward:

and backward:

If a cyclic shift is necessary, repeat this command the required number of times in “for” cycle.