Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
From the dictionary of friends in the lesson, write a function that gives the person with the most friends, and a function that gives the number of friendships. Use only the dictionary.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. The number of friends of a person is the length of the list. Each friendship appears in two lists, so the number of friendships is half the total of the lengths.
Check. The numbers of friends are 2, 3, 2, 2 and 1, so Ravi has the most (3). The total is 10, so there are 5 friendships.
Answer: Ravi 5.
Log in to join the discussion.
Loading…