I can't manage to find people in dictionary if by more than one record.
For example: display people by age+sex+city if given input age, sex, city or sex+city if given input sex, city.
people={'1': {'name': 'John', 'surname': 'Mclachan', 'age': '27', 'city': 'London', 'sex': 'Male', 'married': 'Yes', 'phoneNo': '00001'}, '2': {'name': 'Marie', 'surname': 'Rose', 'age': '22', 'city': 'London', 'sex': 'Female', 'married': 'No', 'phoneNo': '00002'}, '3': {'name': 'Luna', 'surname': 'Stallone', 'age': '24', 'city': 'Edinburgh', 'sex': 'Female', 'married': 'No', 'phoneNo': '00003'}, '4': {'name': 'Peter', 'surname': 'Griffin', 'age': '29', 'city': 'Edinburgh', 'sex': 'Male', 'married': 'Yes', 'phoneNo': '00004'}}
def find_people():
city = input('Input city >> ').title()
surname = input('surname >> ').title()
name_p = input('name >> ').title()
sex = input('sex >> ').title()
age = input('age >> ').title()
if any(record["name"] == name_p or record['city'] == city or record['sex'] == sex or record['age'] == age or record['surname']== surname for record in people.values()):
for x in people:
if people[x]['name'] == name_p and people[x]['city'] == city or people[x]['name'] == name_p or people[x]['city'] == city or people[x]['sex'] == sex
or people[x]['city'] == city and people[x]['sex'] == sex and people[x]['age'] == age:
#if people[x]['name'] == name_p and people[x]['city'] == city:
print('
Person_ID:', x)
print('-------------')
for key, value in people[x].items():
print(key+':', value)
question from:
https://stackoverflow.com/questions/65839551/searching-dictionary-by-record 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…