def sort_key(self, order=None): """Return a canonical key that can be used for sorting. Ordering is based on the size and sorted elements of the partition and ties are broken with the rank. Examples ======== >>> from sympy.utilities.iterables import default_sort_key >>> from sympy.combinatorics.partitions import Partition >>> from sympy.abc import x >>> a = Partition([[1, 2]]) >>> b = Partition([[3, 4]]) >>> c = Partition([[1, x]]) >>> d = Partition([range(4)]) >>> l = [d, b, a + 1, a, c] >>> l.sort(key=default_sort_key); l [{{1, 2}}, {{1}, {2}}, {{1, x}}, {{3, 4}}, {{0, 1, 2, 3}}] """ if order is None: members = self.members else: members = tuple( sorted(self.members, key=lambda w: default_sort_key(w, order))) return self.size, members, self.rank
def sort_key(self, order=None): """Return a canonical key that can be used for sorting. Ordering is based on the size and sorted elements of the partition and ties are broken with the rank. Examples ======== >>> from sympy.utilities.iterables import default_sort_key >>> from sympy.combinatorics.partitions import Partition >>> from sympy.abc import x >>> a = Partition([[1, 2]]) >>> b = Partition([[3, 4]]) >>> c = Partition([[1, x]]) >>> d = Partition([range(4)]) >>> l = [d, b, a + 1, a, c] >>> l.sort(key=default_sort_key); l [{{1, 2}}, {{1}, {2}}, {{1, x}}, {{3, 4}}, {{0, 1, 2, 3}}] """ if order is None: members = self.members else: members = tuple(sorted(self.members, key=lambda w: default_sort_key(w, order))) return self.size, members, self.rank
def _sort_key(arg): return default_sort_key(arg[0].as_independent(x)[1])
def _sorted_args(self): from sympy.utilities.misc import default_sort_key return sorted(self.args, key=lambda w: default_sort_key(w))