import random
map = {1: '张三', 2: '李四', 3: '王五', 4: '赵六', 5: '王麻子', 6: '包子', 7: '豆浆'}
keys = random.sample(map.keys(), 2)
for key in keys:
print(key, map[key])
import random
map = {1: '张三', 2: '李四', 3: '王五', 4: '赵六', 5: '王麻子', 6: '包子', 7: '豆浆'}
keys = random.sample(map.keys(), 2)
for key in keys:
print(key, map[key])
本文标题:Python 随机从字典中抽取数据
本文链接:https://www.haomeiwen.com/subject/dmpwyltx.html
网友评论