查询多个字典中的公共键, 题目实例
每轮比赛 6个人 都有可能得分, 3轮下来都得分的有谁?
import random res1 = random.sample("abcdefg", random.randint(3, 6)) res2 = random.sample("abcdefg", random.randint(3, 6)) res3 = random.sample("abcdefg", random.randint(3, 6)) s1 = {k: random.randint(1, 3) for k in res1} s2 = {k: random.randint(1, 3) for k in res2} s3 = {k: random.randint(1, 3) for k in res3} print(s1) print(s2) print(s3) l = [] for k in s1: if k in s2 and k in s3: l.append(k) print(l)
原文:https://www.cnblogs.com/shijieli/p/10864838.html