Return a sorted list with all the subsets. The list is sorted by the number of elements in the set and then lexicographically. For example: [[], [1], [2], [12]]. Python sorts are guaranteed to be stable, so we can build this sort in a series of two s
(x)
| 41 | def test_subset(self): |
| 42 | |
| 43 | def f(x): |
| 44 | """ Return a sorted list with all the subsets. |
| 45 | |
| 46 | The list is sorted by the number of elements in the set and then |
| 47 | lexicographically. For example: [[], [1], [2], [12]]. Python sorts |
| 48 | are guaranteed to be stable, so we can build this sort in a series |
| 49 | of two sorting steps. |
| 50 | |
| 51 | """ |
| 52 | |
| 53 | subs = list(subsets(x)) |
| 54 | subs.sort() |
| 55 | subs.sort(key = len) |
| 56 | return subs |
| 57 | |
| 58 | self.assertEqual(f('') , [[]]) |
| 59 |