Python 字典/抽认卡问题。从值而不是键开始
我想尝试一下这个抽认卡的想法,为即将到来的测试学习关键词及其含义。我想在python上创建一个字典,我可以用它来帮助解决这个问题。我的想法是向我展示定义,然后我必须猜测已经定义的单词。我已经在下面展示了如何做到这一点,先显示键,然后显示值,但我想让它做相反的事情,但不知道如何实现这一点。下面代码中的术语表指的是我的字典 任何帮助都将不胜感激Python 字典/抽认卡问题。从值而不是键开始,python,Python,我想尝试一下这个抽认卡的想法,为即将到来的测试学习关键词及其含义。我想在python上创建一个字典,我可以用它来帮助解决这个问题。我的想法是向我展示定义,然后我必须猜测已经定义的单词。我已经在下面展示了如何做到这一点,先显示键,然后显示值,但我想让它做相反的事情,但不知道如何实现这一点。下面代码中的术语表指的是我的字典 任何帮助都将不胜感激 def show_flashcard(): """ Show a random key and ask me to define i
def show_flashcard():
""" Show a random key and ask me
to define it. Show the definition
when the user presses return.
"""
random_key = choice(list(glossary))
print('Define: ', random_key)
input('Press return to see the definition')
print(glossary[random_key])
如果我没弄错的话,这还不够吗
print('Define: ', glossary[random_key])
input('Press return to see the definition')
print(random_key)
基本上,只需切换问题和答案。如果我理解正确,这还不够吗
print('Define: ', glossary[random_key])
input('Press return to see the definition')
print(random_key)
基本上只需切换问题和答案。您可以尝试:
def show_flashcard():
""" Show a random definition and ask me
the key. Show the key
when the user presses return.
"""
random_key, random_def = choice(list(glossary.items()))
print('Define: ', random_def)
input('Press return to see the key')
print(random_key)
您可以尝试:
def show_flashcard():
""" Show a random definition and ask me
the key. Show the key
when the user presses return.
"""
random_key, random_def = choice(list(glossary.items()))
print('Define: ', random_def)
input('Press return to see the key')
print(random_key)
谢谢rusu_ro1和Taxel的帮助。谢谢rusu_ro1和Taxel的帮助。