Repository: sympy/sympy

Issue:
Partition can't be ordered
``` python
In [13]: from sympy.combinatorics.partitions import Partition

In [14]: a = Partition([1, 2, 3], [4])

In [15]: b = Partition([1, 2], [3, 4])

In [16]: args = [a, b]
```

Below is the Traceback:

```
In [17]: args = list(ordered(args, Set._infimum_key))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-092459052e8d> in <module>()
----> 1 args = list(ordered(args, Set._infimum_key))

/home/amit/Desktop/myrepo/sympy/sympy/core/compatibility.pyc in ordered(seq, keys, default, warn)
    676                     raise ValueError(
    677                         'not enough keys to break ties: %s' % u)
--> 678         for v in d[k]:
    679             yield v
    680         d.pop(k)

/home/amit/Desktop/myrepo/sympy/sympy/core/compatibility.pyc in ordered(seq, keys, default, warn)
    676                     raise ValueError(
    677                         'not enough keys to break ties: %s' % u)
--> 678         for v in d[k]:
    679             yield v
    680         d.pop(k)

/home/amit/Desktop/myrepo/sympy/sympy/core/compatibility.pyc in ordered(seq, keys, default, warn)
    657         f = keys.pop(0)
    658         for a in seq:
--> 659             d[f(a)].append(a)
    660     else:
    661         if not default:

TypeError: unhashable type: 'list'
```


Discussion:

Patch:
diff --git a/sympy/combinatorics/partitions.py b/sympy/combinatorics/partitions.py
index 788ab0e79f..cb4636abea 100644
--- a/sympy/combinatorics/partitions.py
+++ b/sympy/combinatorics/partitions.py
@@ -88,7 +88,7 @@ def sort_key(self, order=None):
         else:
             members = tuple(sorted(self.members,
                              key=lambda w: default_sort_key(w, order)))
-        return list(map(default_sort_key, (self.size, members, self.rank)))
+        return tuple(map(default_sort_key, (self.size, members, self.rank)))
 
     @property
     def partition(self):


Test patch:
diff --git a/sympy/combinatorics/tests/test_partitions.py b/sympy/combinatorics/tests/test_partitions.py
index 77cb355156..bad40b9508 100644
--- a/sympy/combinatorics/tests/test_partitions.py
+++ b/sympy/combinatorics/tests/test_partitions.py
@@ -1,9 +1,10 @@
-from sympy.core.compatibility import range
+from sympy.core.compatibility import range, ordered
 from sympy.combinatorics.partitions import (Partition, IntegerPartition,
                                             RGS_enum, RGS_unrank, RGS_rank,
                                             random_integer_partition)
 from sympy.utilities.pytest import raises
 from sympy.utilities.iterables import default_sort_key, partitions
+from sympy.sets.sets import Set
 
 
 def test_partition():
@@ -98,3 +99,8 @@ def test_rgs():
     assert RGS_unrank(7, 5) == [0, 0, 1, 0, 2]
     assert RGS_unrank(23, 14) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2]
     assert RGS_rank(RGS_unrank(40, 100)) == 40
+
+def test_ordered_partition_9608():
+    a = Partition([1, 2, 3], [4])
+    b = Partition([1, 2], [3, 4])
+    assert list(ordered([a,b], Set._infimum_key))