Please Write it in Python. AND please in the functioncircleoffriends() i want the logic to account for the numbersfrom 1-n that are not explicitly mentioned in any of thetuples that are not given in the list of tuples and groupthem together and print as a new group of friends. This is alreadymentioned in the question but i wanted to clarify that the examplegiven in the picture is correct. another example would becirlceofriends(9,[(1,2),(2,3),(3,5),(5,7)] the output wouldthen be friend circle 1 : [1,2,3,5,7] friend circle 2 is[4,6,8,9]
Let's assume that two people sharing a friend must be friends themselves. For example, if person 1 and person 2 are friends, and person 2 and person 3 are friends, then person 1 and person 3 must be friends. Write a function CirclesOfFriends(n, 1st) that partitions people in a company into circles of friends. The function takes 2 inputs; n as the total number of people and Is is a list of tuples representing pairs of friends. People who are not part of any circle of friends are automatically placed together in a new circle of friends. The output should be the partition of circles of friends. For example: >>> CirclesOfFriends (7, [(1, 2), (2, 3), (4, 6)]) Friend Circle 1 is [1, 2, 3] Friend Circle 2 is [4, 6] Friend Circle 3 is [5,7]
Please Write it in Python. AND please in the function circleoffriends() i want the logic to account for the numbers fro
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am