#78 · Lists · Intermediate · 70 XP · about 14 min
Write common_items(lists) that takes a list of one or more lists and returns a list of the items that appear in every one of them.
Repeats count: an item appears in the answer as many times as its smallest count across the lists, so an item found at least twice in every list appears twice. Keep the order of the first list, using its earliest copies of each item.
common_items([[1, 2, 3], [3, 1, 4], [5, 1, 3]]) # returns [1, 3] common_items([[2, 1, 2, 3], [2, 2, 1], [1, 2, 4, 2]]) # returns [2, 1, 2] common_items([['x', 'y']]) # returns ['x', 'y'] common_items([[1, 2], []]) # returns []
In the second example 2 appears twice in every list and 1 once, so the answer holds two 2s and one 1, in the order of the first list.
1 <= len(lists) <= 100Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.