zoukankan      html  css  js  c++  java
  • 字典公共键

    from functools import reduce
    import random
    s1 = {x: random.randint(1,4) for x in random.sample('abcdefg',random.randint(3,6))}#七名球员随机选取3-6个各进球随机1-4个
    s2 = {x: random.randint(1,4) for x in random.sample('abcdefg',random.randint(3,6))}
    s3 = {x: random.randint(1,4) for x in random.sample('abcdefg',random.randint(3,6))}
    #方案1:
    res=[]
    for k in s1:
    if k in s2 and k in s3:
    res.append(k)
    print(res)

    #方案2:
    allKeys = map(dict.keys,[s1,s2,s3])
    sameK = reduce(lambda a,b:a & b,allKeys)
    print(sameK)

    输出:

  • 相关阅读:
    基于typora编写Markdown文档
    VMware Workstation常见的故障处理
    VMware Workstation产品常用的快捷键
    2
    1
    9
    8
    7
    6
    5
  • 原文地址:https://www.cnblogs.com/cxxBoo/p/11625229.html
Copyright © 2011-2022 走看看