【发布时间】:2012-11-07 20:55:25
【问题描述】:
我想知道 python 使用random.choice 选择哪个列表,以便我可以使用if 语句来获得不同的结果。
thelists = [L1, L2, L3, L4, L5, L6]
theplayers = random.choice(thelists)
我想知道选择 theplayers 的变量是哪个列表,L1,L2...。
【问题讨论】:
-
或者,
index, lst = random.choice(list(enumerate(thelists)))或使用哈希而不是列表并执行list_name, lst = random.choice(thehashoflists.items())