Common Item Frequency
Start Timer
0:00:00
Given a list of (name, item) pairs, pair_list, write a function common_items to create a list of (name1, name2, item_frequency) triples where item_frequency is the number of common items shared between the two names.
Make sure all possible name pairs are included, there are no duplicate name pairs, there are no pairs of the same name, and the order of the names is alphabetical.
Example:
Input:
pair_list = [('Susan', 'spoon'),
('Susan', 'fork'),
('Mark', 'fork'),
('Mark', 'spoon'),
('Mark', 'plate'),
('Lily', 'plate')]
Output:
def common_items(pair_list) -> [
('Lily',' Mark', 1),
('Lily', 'Susan', 0),
('Mark', 'Susan', 2),
]
.
.
.
.
.
.
.
.
.
Comments