# ANY - if any element evaluate to true
# ALL - if all elements evaluete to true
friends = [
{'name': 'Rolf', 'Location': 'Warszawa'},
{'name': 'Piotr', 'Location': 'Warszawa'},
{'name': 'Marek', 'Location': 'Warszawa'},
{'name': 'Tomasz', 'Location': 'Kraków'},
{'name': 'Zenek', 'Location': 'Warszawa'},
{'name': 'Stanislaw', 'Location': 'Warszawa'}
]
yourlocation = input('Where are u?')
friends_nearby = [friend for friend in friends if friend['Location'] == yourlocation ]
if any(friends_nearby): # if there is at least one and False if empty
print("u are not alone")
if all(friends_nearby):
print("u are not alone")
#Values that evaluate to false
"""
0 , 0.0 ...
none
[] () {}
False
"""
#print(bool(0))
print(all([1, 2, 3, 4, 5]))
print(all([0, 1, 2, 3, 4, 5]))
Comments