【发布时间】:2012-02-21 18:44:05
【问题描述】:
有没有办法将变量传递给choice() 函数以获取列表。我有一堆列表,我想从一个列表中随机选择,然后使用返回的字符串从具有该字符串名称的列表中进行选择。
A = ['1','2','3']
print choice (A) - this gets me a random choice from the list
但我想将选择存储为变量并用它来调用另一个列表
A = ['1','2','3']
1 = ['A','B','C']
Var1 = choice (A)
print choice (Var1) *** this is my problem, how do I pass a variable to the choice function
感谢您的帮助!
【问题讨论】:
-
1 = ['A','B','C']?!神圣的****! -
...它以“d”开头...并以“t”结尾。它有四个字母长。使用dict。
标签: python list variables random