print('-----------smart health prediction using data mining------------------- ')
mydict = {
'malaria': ['fever', 'headache', 'sweats', 'chills', 'vomiting'],
'anxiety': ['restlessness', 'a sense of dread', 'feeling constantly on edge', 'difficulty concentrating', 'irritability'],
'asthma': ['wheezing (a whistling sound when you breathe)', 'shortness of breath', 'a tight chest – which may feel like a band is tightening around it', 'Coughing'],
'hepatitis C': ['shortness of breath', 'angina pectoris', 'anorexia', 'sinus rhythm'],
'diabetes': ['feeling very thirsty', 'feeling very tired', 'wight loss and loss of muscle in mulk'],
'migraine': ['increased sensitivity to light and sound', 'vomiting', 'feeling very tierd', 'headache']
}
print(mydict)
j = input("How many symptoms")
x = int(j)
list1 = []
for i in range(x):
list1.append(input())
print (list1)
# From here I want the list to match the maximum symptoms with the lists in the dictionary
if list1 == mydict['malaria']
print('true')
else:
print('false')
mydict['malaria'], mydict['anxiety']
Tags:
我有几个建议在这里应该会有所帮助
set
,而不是一个list
。为什么?集合是无序的,易于比较和操作。你不在乎症状的顺序,你只想看看有多少匹配。正如您将在下面看到的,使用集合更容易做到这一点李>我用精确匹配来解决这个问题的代码(我注意到一些拼写错误,我只是保持原样):
这应该提供更容易的(无序的)匹配,并且应该显示与输入症状数量最多的匹配的任何紊乱。它不处理领带,但如果需要的话,您可以解决这些细节问题
希望这有帮助,快乐编码
您可以使用
check = all(item in mydict[i] for item in list1)
检查列表中的所有元素是否都在字典的列表中,即使您可以这样做相关问题 更多 >
编程相关推荐