Round-Trip Between Tuple, List and Set

Hard ⏱ 18 min 32% acceptance ★★★★☆ 4.2
Implement dedupe_sorted_tuple(items) that takes an iterable of ints and produces an immutable, deduplicated, ascending-order tuple by explicitly converting between all three container types: first to a set (drops duplicates), then to a list (so it can be sorted in place), then finally back to a tuple to return.

Examples

Example 1
Input
dedupe_sorted_tuple([3, 1, 2, 3, 1])
Output
(1, 2, 3)
Explanation

Duplicates removed via set, then sorted, then returned as a tuple.

Example 2
Input
dedupe_sorted_tuple((5, 5, 5))
Output
(5,)
Explanation

A single-element result is still a 1-tuple.

Constraints

  • items may be a list, tuple, or other iterable of ints.
  • Must perform all three conversions (set, list, tuple) rather than a single one-line shortcut.

Topics

TuplesSets

Companies

Deutsche BankGoldman Sachs

Hints

Hint 1

set(items) removes duplicates but loses order.

Hint 2

list(a_set) makes it sortable with .sort().

Hint 3

tuple(a_sorted_list) produces the final immutable result.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.