python 如何一次隨機取出多條資料(能重複/不能重複)

weixin_33866037發表於2018-04-12

取出的資料可以重複

need=[random.randint(0,100) for _ in range(要取出的資料條數)]

# 隨機抽取3個測試題
exam_choice_list = [random.choice(exam_msg_list) for _ in range(3)]
7052492-9c91fa61a2faeda1.png
image.png

取出的資料不能重複

need = random.sample([要取資料的列表], 要取出的資料個數)

exam_choice_list = random.sample(exam_msg_list, 3)
7052492-4d85b6a64efccf86.png
image.png

相關文章