Write a function friend_besties() that calculates the "besties" (i.e. degree-one friends) of a given individual in a social network. The function takes two arguments: individual, an individual in the social network, in the form of a string ID. bestie_dict, a dictionary of sets of friends of each individual in the social network (as per the first question of the Project) The function should return a sorted list, made up of all "degree-one" friends for the individual. In the instance that the individual does not have any friends in the social network, the function should return an empty list. Example function calls are: >>> friend_besties('kim', {'kim': {'sandy', 'alex', 'glenn'}, 'sandy': {'kim', 'alex'}, 'alex': {'kim', 'sandy'}, 'glenn': {'kim'}}) ['alex', 'glenn', 'sandy'] >>> friend_besties('ali', {'kim': {'sandy', 'alex', 'glenn'}, 'sandy': {'kim', 'alex'}, 'alex': {'kim', 'sandy'}, 'glenn': {'kim'}})
Write a function friend_besties() that calculates the "besties" (i.e. degree-one friends) of a given individual in a social network. The function takes two arguments:
- individual, an individual in the social network, in the form of a string ID.
- bestie_dict, a dictionary of sets of friends of each individual in the social network (as per the first question of the Project)
The function should return a sorted list, made up of all "degree-one" friends for the individual. In the instance that the individual does not have any friends in the social network, the function should return an empty list.
Example function calls are:
>>> friend_besties('kim', {'kim': {'sandy', 'alex', 'glenn'}, 'sandy': {'kim', 'alex'}, 'alex': {'kim', 'sandy'}, 'glenn': {'kim'}})
['alex', 'glenn', 'sandy']
>>> friend_besties('ali', {'kim': {'sandy', 'alex', 'glenn'}, 'sandy': {'kim', 'alex'}, 'alex': {'kim', 'sandy'}, 'glenn': {'kim'}})
[]
Subject: Python Programming
Step by step
Solved in 2 steps with 2 images