easy +10 pts

Set symmetric difference

Compute the symmetric difference of two sets and return it as a sorted list.

Write a function `symmetric_difference_sorted(a, b)` that takes two iterables (e.g., lists, sets, tuples) `a` and `b` and returns a list of all elements that appear in exactly one of them, sorted in ascending order. - The input may contain duplicates, but the output must contain each unique element only once. - The output must be a list of numbers sorted in ascending numeric order. - The function must work for any hashable elements? **Note:** Assume the elements are integers (for sorting consistency). Implement the function so that it returns a list, not a set.

Constraints

Input lengths are between 0 and 10^5. Elements are integers. Expected time complexity O(n log n) due to sorting, with O(n) space.

Example

>>> symmetric_difference_sorted([1, 2, 3], [2, 3, 4])
[1, 4]
>>> symmetric_difference_sorted([5, 5, 6], [5])
[6]
>>> symmetric_difference_sorted([], [])
[]
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Convert both inputs to sets to remove duplicates.
The symmetric difference contains elements in either set but not both.
Convert the result to a sorted list before returning.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.