MCPcopy Index your code
hub / github.com/careercup/ctci / f

Method f

python/Chapter 9/Question9_04/subsets.py:43–56  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

subsetsFunction · 0.85
sortMethod · 0.45

Tested by

no test coverage detected