# -*- coding = utf-8 -*-
from random import randint, sample
from functools import reduce
s1 = {x: randint(1, 5) for x in sample('abcdefg', 3)}
s2 = {x: randint(1, 5) for x in sample('abcdefg', 3)}
s3 = {x: randint(1, 5) for x in sample('abcdefg', 3)}
print(s1, s2, s3, sep='\n')
res = []
for k in s1:
if k in s2 and k in s3:
res.append(k)
print(res)
# map() 将可迭代对象中每个元素都作用了 dict.keys
print(map(dict.keys, [s1, s2, s3]))
# print(reduce(lambda a, b: a & b, map(dict.keys, [s1, s2, s3])))
# reduce 按顺序的将两个元素进行 & 操作,找出其中的公有部分
a = reduce(lambda a, b: a & b, map(dict.keys, [s1, s2, s3]))
for tmp in a:
print(tmp)