(Python3) Write a function friend_besties() that calculates the \"besties\" (i.e. degree-one friends) of a given individual in...

50.1K

Verified Solution

Question

Programming

(Python3)

Write a function friend_besties() that calculates the \"besties\"(i.e. degree-one friends) of a given individual in a socialnetwork. The function takes two arguments:

  • individual, an individual in the social network, in the form ofa string ID.
  • bestie_dict, a dictionary of sets of friends of each individualin the social network (as per the first question of theProject)

The function should return a sorted list, made up of all\"degree-one\" friends for the individual. In the instance that theindividual does not have any friends in the social network, thefunction should return an empty list.

Example:

>>> 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'}})
[]

Answer & Explanation Solved by verified expert
3.9 Ratings (755 Votes)
Note Please indent the code as per the provide codescreenshot Otherwise it raises indentation    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students