Sorting a list of frozensets?

526 Views Asked by At

Is it possible to lexicographically sort a list of frozensets as in the following example:

sort_frozensets(frozenset(['d','b']), frozenset(['a','b']), frozenset(['z','a']), frozenset(['l',''m]))
#result = frozenset(['a','b']), frozenset(['z','a']), frozenset(['d','b']), frozenset(['l',''m])

So, it's ordered through the order of the first item, and if the first item is the same, then the second item is considered.

1

There are 1 best solutions below

0
psarka On

No, frozensets do not have an order, so you can't sort them. Find another data structure that fits your problem, we won't be able to guess it.