Intermediate · Sets · 145 of 264
In just one list
Print the numbers that are in exactly one of the two lists, sorted.
Input: two lines of whole numbers. Output: those numbers in ascending order, or none
Examples
Input
1 2 3 2 3 4
Output
1 4
Input
1 2 1 2
Output
none
Input
5 6
Output
5 6
One more test checks other inputs when you press Check.
Stuck? The idea behind sets
A set holds each value once, in no particular order: set(list) drops repeats at once.
Checking whether a value is in a set is fast. & keeps what two sets share, | joins them, - keeps what is only in the first.
a = set(input().split()) b = set(input().split()) print(sorted(a & b))
Watch for: A set has no order: sort it (sorted()) before printing, or the order may change.