Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read two lines of integers. Print the values that appear on both lines, sorted ascending.
A set intersection is exactly 'values that live in both collections'.
Input. Two lines, each space-separated integers.
Output. The common values, sorted, space-separated. If none, a blank line.
Examples
Input
1 2 3 4 3 4 5
Output
3 4
Input
1 2 3 4
Output
Hint
- set(a) & set(b) is the intersection.
- sorted(...) then print(*...).
Show correct code
Peek only after you have tried. You can still Check your own version.
a = set(map(int, input().split()))
b = set(map(int, input().split()))
print(*sorted(a & b))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.