有沒有辦法將一個變量傳遞給列表的choice()
函數。我有一堆列表,我想從一個列表中隨機選擇,然後使用返回的字符串從具有該字符串名稱的列表中進行選擇。Python中的隨機列表選項
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']'?!聖****! – 0605002 2012-01-29 19:27:16
...它以'd'開頭......以't'結尾。這是四個字母。使用[dict](http://docs.python.org/tutorial/datastructures.html#dictionaries)。 – 2012-01-29 23:41:31