Python 随机从字典中抽取数据
2021-06-24 本文已影响0人
还是那个没头脑
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])