Tuples and sets · 15 / 16 Exercise Hard

Words with the same letters

Objective

Sets cannot be used as dictionary keys, but frozenset (immutable sets) can. They serve to group by “which letters appear”, regardless of order or repetitions.

Instructions

  • The first line has the number n of words; then one per line (lowercase, letters only).
  • Group the words that have the same set of distinct letters (for example abba and baab). Show one group per line with its words without repeats and sorted alphabetically, separated by a space, and the groups sorted.
Input
6
listen
silent
abba
ab
baab
enlist
Output
ab abba baab
enlist listen silent

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise