我正在寻找一种优雅的方法来编写一个简单的函数,该函数会将列表的元素移动给定数量的位置,同时保持列表的长度相同并用默认值填充空位置。这将是该函数的文档字符串:
def shift_list(l, shift, empty=0):
"""
Shifts the elements of a list **l** of **shift** positions,
padding new items with **empty**::
>>> l = [0, 1, 4, 5, 7, 0]
>>> shift_list(l, 3)
[0, 0, 0, 0, 1, 4]
>>> shift_list(l, -3)
[5, 7, 0, 0, 0, 0]
>>> shift_list(l, -8)
[0, 0, 0, 0, 0, 0]
"""
pass
你将如何进行?非常感谢任何帮助!