Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Find values that appear in exactly one of two sets

Return the unique values that are present in one collection but not both, presented in sorted order.

Python practice26 minDictionaries & SetsAdvancedLast updated March 18, 2026

Problem statement

Write a function values_in_exactly_one(a, b) that accepts two iterables (like lists or tuples). Determine which values appear in exactly one of the two inputs (i.e., the symmetric difference). Return the result as a sorted list of unique values. Sorting ensures predictable output for testing. You may assume elements within each input are of a type that can be compared with each other (e.g., all ints or all strings).

Task

Given two iterables, compute the values that appear in exactly one of them and return a sorted list of those unique values.

Examples

Simple symmetric difference

Input

values_in_exactly_one([1, 2, 3], [3, 4])

Output

[1, 2, 4]

1 and 2 are only in the first; 4 is only in the second.

Input format

Two iterables passed as arguments: values_in_exactly_one(a, b).

Output format

Return a sorted list containing values that appear in exactly one of the inputs.

Constraints

- Elements within each input are comparable (so sorted() works). - Inputs may contain duplicates; the result should contain each unique value once. - Do not use any external libraries.

Samples

Sample 1

Input

values_in_exactly_one(['a', 'b', 'b'], ['b', 'c'])

Output

['a', 'c']

Unique values only in one side are 'a' and 'c', returned sorted.