python matching people based on city

Solutions on MaxInterview for python matching people based on city by the best coders in the world

showing results for - "python matching people based on city"
Stanislas
22 Oct 2018
1students = [
2    {
3     'name': 'Sarah',
4     'city': 'Manchester'
5    },
6    {
7     'name': 'Mary',
8     'city': 'London'
9     }
10    ,
11    {
12     'name': 'Charlotte',
13     'city': 'Paris'
14     },
15    {
16     'name': 'Carl',
17     'city': 'Paris'
18     }  
19]
20
21 
22
23my_location = input('Which is your location?  ')
24match_location = [student for student in students if student['city'] == my_location]
25 
26  
27# Option 1     
28if len(match_location) > 0:
29    print('The location is:')    
30    
31    
32# Option 2
33if any(match_location):
34    print('The location is:')