# 找到重叠的键

xiaoxiao2021-03-26  17

map(function, iterable, ...)

Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed,function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended withNoneitems. If function isNone, the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation). The iterable arguments may be a sequence or any iterable object; the result is always a list.

python中的reduce内建函数是一个二元操作函数，他用来将一个数据集合（链表，元组等）中的所有数据进行下列操作：用传给reduce中的函数 func()（必须是一个二元操作函数）先对集合中的第1，2个数据进行操作，得到的结果再与第三个数据用func()函数运算，最后得到一个结果。

from random import randint

from random import sample s=[1,2,3] s1= {x:randint(1,4) for x in sample('abcdefg',randint(3,6))} s2= {x:randint(1,4) for x in sample('abcdefg',randint(3,6))} s3= {x:randint(1,4) for x in sample('abcdefg',randint(3,6))} res=[] for k in s1:     if k in s2 and k in s3:         res.append(k) print res c= s1.viewkeys() & s2.viewkeys() &s3.viewkeys() print c c2=map(dict.viewkeys,[s1,s2,s3]) print c2 c3=reduce(lambda a ,b :a & b,map(dict.viewkeys,[s1,s2,s3])) print c3