📜  python - 根据城市匹配人 - Python代码示例

📅  最后修改于: 2022-03-11 14:46:30.331000             🧑  作者: Mango

代码示例1
students = [
    {
     'name': 'Sarah',
     'city': 'Manchester'
    },
    {
     'name': 'Mary',
     'city': 'London'
     }
    ,
    {
     'name': 'Charlotte',
     'city': 'Paris'
     },
    {
     'name': 'Carl',
     'city': 'Paris'
     }  
]

 

my_location = input('Which is your location?  ')
match_location = [student for student in students if student['city'] == my_location]
 
  
# Option 1     
if len(match_location) > 0:
    print('The location is:')    
    
    
# Option 2
if any(match_location):
    print('The location is:')