Messenger logs arrive as a list of (sender, receiver) tuples. Write chattiest_pair(messages) returning the pair of people who messaged each other the most, counting both directions together, as a tuple with the two names in alphabetical order. If pairs tie, return the one that comes first alphabetically. Return None for an empty log.
Example
chattiest_pair([("ana", "ben"), ("ben", "ana"), ("cam", "ana")])('ana', 'ben')What this question tests
Tests building a key that does not care about order. A message from Ana to Ben and one from Ben to Ana belong to the same conversation, and the fix (sort the two names into a tuple) is the kind of small idea data-engineering rounds at Meta are reported to lean on.
More Python interview questions