#45 · Graphs · Beginner · 40 XP · about 8 min
On a photo app, following goes one way: Ana can follow Ben without Ben following her back. The dictionary follows maps each user to the list of users they follow. Write mutual_follows(follows) that finds every pair of users who follow each other.
Return a list of tuples (a, b), where a comes before b alphabetically, with the whole list sorted. Some users appear only inside other users' lists, which means they follow nobody.
mutual_follows({'ana': ['ben', 'cy'], 'ben': ['ana'], 'cy': ['ben']}) # returns [('ana', 'ben')] mutual_follows({'kim': ['lee'], 'lee': ['kim', 'max'], 'max': ['lee', 'kim']}) # returns [('kim', 'lee'), ('lee', 'max')]
In the first example Cy follows Ben, but Ben does not follow Cy back, so Ana and Ben are the only mutual pair.
First solves only, ranked by stars and then time.