Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Three clubs have these members.
Find the students who are in exactly two clubs.
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. One way is to count the clubs of each student with a dictionary. Another is to use the set operations.
With a dictionary.
With sets. A student is in exactly two clubs if the student is in a pair of clubs, but not in the third. Take the three pair overlaps, join them, and take away the students who are in all three.
Check. By hand: Asha is in cricket and music (2). Ravi is in cricket and chess (2). Kabir is in chess and music (2). Meera is in all three (3). Dev and Ana are in one.
Answer: ['Asha', 'Kabir', 'Ravi'].
Log in to join the discussion.
Loading…