forked from kishanrajput23/Awesome-Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFriends.py
More file actions
20 lines (14 loc) · 749 Bytes
/
Friends.py
File metadata and controls
20 lines (14 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#Ask a user for a list of 3 friends.
#For each friend of user We'll tell whether he/she is nearby.
#For every nearby friend we'll save their names in "nearby_friends.txt0".
friends = input("Enter names of 3 friends: ").split(",")
with open("people.txt", "r") as people:
nearby_people = [line.strip() for line in people.readlines()] # With open automatically opens and closes the file.
my_friend = set(friends)
nearby = set(nearby_people)
friends_nearby_set = my_friend.intersection(nearby)
with open("nearby_friends.txt", "w") as nearby_friends_file:
for friend in friends_nearby_set:
nearby_friends_file.write(f"{friend}\n")
print(f"{friend} is nearby, let's meet up")
nearby_friends_file.close()