Common Elements
beginnerUp next
Up next
Output will appear here...
The starter code reads two lists of integers, a and b. Print the numbers that appear in both, each only once, sorted from smallest to largest, separated by spaces. If the lists have nothing in common, print none.
For the inputs 1 2 3 4 and 3 4 5 6, a correct solution prints:
3 4
Tip
The set intersection operator & finds the shared items. Use sorted() to turn the result into an ordered list. An empty set counts as falsy, which can help with the none case.
No comments yet. Start the discussion.