Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/sage/combinat/set_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def _repr_(self):
sage: S([[1,3],[2,4]])
{{1, 3}, {2, 4}}
"""
return '{' + ', '.join('{' + repr(sorted(x))[1:-1] + '}' for x in self) + '}'
try:
s = [sorted(x) for x in self]
except TypeError:
s = [sorted(x, key=str) for x in self]
return '{' + ', '.join('{' + repr(x)[1:-1] + '}' for x in s) + '}'

def __hash__(self):
"""
Expand Down Expand Up @@ -532,7 +536,7 @@ def pre_conjugate(sp):


class SetPartition(AbstractSetPartition,
metaclass=InheritComparisonClasscallMetaclass):
metaclass=InheritComparisonClasscallMetaclass):
r"""
A partition of a set.

Expand Down Expand Up @@ -620,7 +624,11 @@ def __init__(self, parent, s, check=True):
{}
"""
self._latex_options = {}
ClonableArray.__init__(self, parent, sorted(map(frozenset, s), key=min), check=check)
try:
s = sorted(map(frozenset, s), key=min)
except TypeError:
s = sorted(map(frozenset, s), key=lambda b: min(str(b)))
ClonableArray.__init__(self, parent, s, check=check)

def check(self):
"""
Expand Down Expand Up @@ -2821,7 +2829,11 @@ def __iter__(self):
sage: SetPartitions(["a", "b"]).list()
[{{'a', 'b'}}, {{'a'}, {'b'}}]
"""
for sp in set_partition_iterator(sorted(self._set)):
try:
s = sorted(self._set)
except TypeError:
s = sorted(self._set, key=str)
for sp in set_partition_iterator(s):
yield self.element_class(self, sp, check=False)

def base_set(self):
Expand Down Expand Up @@ -3179,7 +3191,11 @@ def __iter__(self):
sage: SetPartitions(["a", "b", "c"], 2).list()
[{{'a', 'c'}, {'b'}}, {{'a'}, {'b', 'c'}}, {{'a', 'b'}, {'c'}}]
"""
for sp in set_partition_iterator_blocks(sorted(self._set), self._k):
try:
s = sorted(self._set)
except TypeError:
s = sorted(self._set, key=str)
for sp in set_partition_iterator_blocks(s, self._k):
yield self.element_class(self, sp, check=False)

def __contains__(self, x):
Expand Down