【发布时间】:2022-01-22 20:35:50
【问题描述】:
如果一个接收者在每个类别中拥有最多,你必须返回他的名字。如果没有所有类别中值最多的接收者,则应返回“无”。
receivers = ({'abdul': {'a': 1800, 'b': 18, 'c': 117},
'ahmed' : {'a': 1700, 'b': 17, 'c': 116},
'rehman' : {'a': 1750,'b': 16, 'c': 113}})
def triple_crown(receivers):
aa= [j['a'] for i,j in l.items()]
bb= [j['b'] for i,j in l.items()]
cc= [j['c'] for i,j in l.items()]
p = ['abdul', 'ahmed', 'rehman']
for i,j in enumerate(list(zip(aa,bb,cc))):
x,y,z=j
if x==max(aa) and aa.count(x)==1:
if y==max(bb) and bb.count(y)==1:
if z==max(cc) and cc.count(z)==1:
return p[i]
else:
return 'None of them'
输出应该是“abdul”,因为他的 a、b 和 c 值比他的同行多
我以这种方式定义了函数,但我想应该有更好的方法来做到这一点,因为这是一个非常糟糕的解决方案
【问题讨论】:
标签: python python-3.x dictionary