gpt4 book ai didi

python - 如何在包含列表的字典中查找值的组合?

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:40 25 4
gpt4 key购买 nike

list_match= {"Mada":["yellow","green",],"Alexa":["blonde","brown"],"Sasha":["blue","readhead"],"Andreea":["cameleonic","brunett"]}

print ('welcome to the "Find your match quiz"')
print ("Let/'s begain")

eyes = input ("How should the eyes be?")
hair=input("How do you want the the hair to be?")

def cf(response,cond1,cond2,cond3,cond4):
if response == (cond1):
return response
if response == (cond2):
return response
if response == (cond3):
return response
if response ==(cond4):
return response
else:
return ("We don't have knowledge of this characteristic.")

cf(eyes,"green","brown","blue","cameleonic")
cf(hair,"yellow","blonde","readhead","brunett")

所以......我想做一个小“寻找你的匹配”程序。我决定制作一个可以用于女孩不同特征的功能......“金发”头发......“蓝色”眼睛……等等嗯...问题是我不知道如何查找函数的组合结果: cf(response,con1,cond2,cond3,cond4) ,我想组合函数的这两个结果:

cf(eyes,"green","brown","blue","cameleonic")
cf(hair,"yellow","blonde","readhead","brunett")

所以我可以在上面的字典中查找结果之间的组合,以获得该字典中每个真实组合的 key ,最后打印女孩的名字加上“你找到了一个匹配”字符串...

最佳答案

以下列表理解将给出具有匹配属性的名称列表:

[k for k, v in list_match.items() if v[0] == eyes and v[1] = hair]

关于python - 如何在包含列表的字典中查找值的组合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41419273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com