I'll go ahead and post a couple answers.
(我将继续发布一些答案。)
The easiest way to get some of a list is using slice
notation: (获取列表的最简单方法是使用slice
符号:)
pl = pl[:5] # get the first five elements.
If you really want to pop from the list this works:
(如果您真的想从列表中弹出,则可以这样做:)
while len(pl) > 5:
pl.pop()
If you're after a random selection of the choices from that list, this is probably most effective:
(如果您是从该列表中随机选择选项,那么这可能是最有效的:)
import random
random.sample(range(10), 3)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…