Я предполагаю, что вы делаете викторину. Для такого приложения я написал функцию, которая выглядит следующим образом:
def shuffle(q):
"""
The input of the function will
be the dictionary of the question
and answers. The output will
be a random question with answer
"""
selected_keys = []
i = 0
while i < len(q):
current_selection = random.choice(q.keys())
if current_selection not in selected_keys:
selected_keys.append(current_selection)
i = i+1
print(current_selection+'? '+str(q[current_selection]))
Если я дам вход questions = {'VENEZUELA':'CARACAS', 'CANADA':'TORONTO'}
и вызову функцию shuffle(questions)
, тогда вывод будет следующим:
VENEZUELA? CARACAS CANADA? TORONTO
Вы можете расширить это еще больше, перетасовывая параметры, и я надеюсь, что это поможет. Источник: РАДИУС КРУГА