小编kid*_*eme的帖子

从Python中的字典中提取彼此不相等的随机密钥

所以我试图通过Python设置多项选择测验.我对Python很陌生,所以如果有更简单的方法可以预先表示道歉.但是,在尝试更新的技术之前,我正试图真正理解一些基础知识.

我有一本字典.在这本字典中,我想要抓住3个随机密钥.我还想确保这三个键不相等(换句话说,彼此随机).这是我到目前为止写的代码:

import random

word_drills = {'class': 'Tell Python to make a new kind of thing.',
               'object': 'Two meanings: the most basic kind of thing, and any instance of some thing.',
               'instance': 'What you get when you tell Python to create a class.',
               'def': 'How you define a function inside a class.',
               'self': 'Inside the functions in a class, self is a variable for the instance/object being accessed.',
               'inheritance': 'The concept that one class can inherit traits from another class, …
Run Code Online (Sandbox Code Playgroud)

python dictionary function python-2.7

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

dictionary ×1

function ×1

python ×1

python-2.7 ×1