我在用python slicing从一个列表中取元素,但不知道里面的元素会不会够用。
目前我是这样做的,感觉很丑。
if index + num_to_take > len(values):
bit = values[index: ]
else:
bit = values[index:index + num_to_take]
有没有更好的方法?
没有必要的如果
bit = values[index:index + num_to_take]
行得通