I am practicing python by doing some projects, and I am stuck on this function. I'd like to know how to do it without using statements like break, input, print, or continue.

The first parameter represents a person to friends dictionary, the second parameter represents a person to clubs dictionaP2F = {Jesse Katsopolis: [Danny R Tanner, Joey Gladstone, Rebecca Donaldson-Katsopolis], Rebecca Donaldson-Katsopoli

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Please find the solution given below, if you have any doubts in it please ask me in comment section.Thank You


Code to Copy:

P2F = {
   'Jesse Katsopolis': ['Danny R Tanner', 'Joey Gladstone',
   'Rebecca Donaldson-Katsopolis'],
   'Rebecca Donaldson-Katsopolis': ['Kimmy Gibbler'],
   'Stephanie J Tanner': ['Michelle Tanner', 'Kimmy Gibbler'],
   'Danny R Tanner': ['Jesse Katsopolis', 'DJ Tanner-Fuller',
   'Joey Gladstone']

P2C = {
   'Michelle Tanner': ['Comet Club'],
   'Danny R Tanner': ['Parent Council'],
   'Kimmy Gibbler': ['Rock N Rollers', 'Smash Club'],
   'Jesse Katsopolis': ['Parent Council', 'Rock N Rollers'],
   'Joey Gladstone': ['Comics R Us', 'Parent Council']

def recommend_clubs(
                   person_to_friends: Dict[str, List[str]],
                   person_to_clubs: Dict[str, List[str]],
                   person: str,) -> List[Tuple[str, int]]:
                   Return a list of club recommendations for person based on the
                   "person to friends" dictionary person_to_friends and the "person
                   to clubs" dictionary person_to_clubs using the specified
                   recommendation system.
                   club_recommendations = {}
                   if person in person_to_friends.keys():#check whether given person is in person_to_frinds dictionary
                       friends = person_to_friends[person]#get the corresponding person's friends list
                       print("Given \"{}\" person coundn't find in P2F dictionary".format(person))
                   for friend in friends:#iterate over a friends list
                       if friend in P2C.keys():
                           clubs = P2C[friend]
                           for club in clubs:
                               count = 1
                               if club not in club_recommendations:
                                   club_recommendations[club] = count# add recommended club into club_recommendations dict
                                   club_recommendations[club] += 1#if club is aready present in dict the increment its recommendation count

                           #print("\"{}\" coundn't find in P2C dictionary\n".format(friend))

                   club_recommendation_list = (list(club_recommendations.items())) #convert dictionary of items to a list

                   return club_recommendation_list

if __name__ == '__main__':
       club_recommendation_list = recommend_clubs(P2F,P2C,'Stephanie J Tanner')

Screenshot of code:

Screenshot of Output;

Add a comment
Know the answer?
Add Answer to:
I am practicing python by doing some projects, and I am stuck on this function. I'd...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.