runtime
159 / 500
question 159 Collections & Itertools · medium

The two users with the most in common

A Q&A site introduces users who answer questions on the same topics. Write most_similar_pair(users): return the names of the two users who share the most distinct tags, as a (name, name) tuple in the order combinations produces pairs. If several pairs share the same number, return the first of them. Return None when there are fewer than two users or no pair shares any tag.

Functionmost_similar_pair(users)
usersa list of dictionaries with name and tags (a list of texts; a user's list may repeat a tag)
Returnsa (name, name) tuple, or None
Examples
callmost_similar_pair([{'name': 'maya-k', 'tags': ['python', 'pandas', 'datetime']}, {'name': 'devon-r', 'tags': ['rust', 'cli']}, {'name': 'lena-o', 'tags': ['pandas', 'python', 'numpy']}, {'name': 'sam-t', 'tags': ['python', 'cli']}])returns('maya-k', 'lena-o')
callmost_similar_pair([{'name': 'devon-r', 'tags': ['rust', 'cli']}, {'name': 'lena-o', 'tags': ['pandas', 'python', 'numpy']}, {'name': 'sam-t', 'tags': ['python', 'cli']}])returns('devon-r', 'sam-t')
callmost_similar_pair([{'name': 'maya-k', 'tags': ['python', 'pandas', 'datetime']}])returnsNone

Loading your progress…

The two users with the most in common — Python practice · Runtime