Who is keller

"""

Who is the killer?
Some people have been killed!
You have managed to narrow the suspects down to just a few.
Luckily, you know every person who those suspects have seen on the day of the murders.

Task.
Given a dictionary with all the names of the suspects and everyone that they have seen on that day which may look like this:

{'James': ['Jacob', 'Bill', 'Lucas'],
 'Johnny': ['David', 'Kyle', 'Lucas'],
 'Peter': ['Lucy', 'Kyle']}

and also a list of the names of the dead people:

['Lucas', 'Bill']

return the name of the one killer, in our case 'James' because he is the only person that saw both 'Lucas' and 'Bill'

"""


# def killer(suspect_info, dead):
#     lstkey = list(suspect_info.keys())
#     lstvalue = list(suspect_info.values())
#     count = 0
#     for i in range(len(lstvalue)):
#         for j in range(len(lstvalue[i])):
#             for k in range(len(dead)):
#                 if dead[k] == lstvalue[i][j]:
#                     count += 1
#             if count == len(dead):
#                 return lstkey[i]

# other anwser
# set() 函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集、差集、并集等。
def killer(info, dead):
    for name, seen in info.items():
        if set(dead) <= set(seen):
            return name


print(killer({'James': ['Jacob', 'Bill', 'Lucas'],
              'Johnny': ['David', 'Kyle', 'Lucas'],
              'Peter': ['Lucy', 'Kyle']},
             ['Lucas', 'Bill']))

print(killer({'Brad': [],
              'Megan': ['Ben', 'Kevin'],
              'Finn': []},
             ['Ben']))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值