Skip to content

Commit bdf7bca

Browse files
committed
-
1 parent d5dc326 commit bdf7bca

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

source_py3/python_toolbox/combi/selection_space.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@
2424

2525
class SelectionSpace(sequence_tools.CuteSequenceMixin,
2626
collections.Sequence):
27+
'''
28+
Space of possible selections of any number of items from `sequence`.
29+
30+
For example:
31+
32+
>>> tuple(combi.SelectionSpace(range(2)))
33+
(set(), {1}, {0}, {0, 1})
34+
35+
The selections (which are sets) can be for any number of items, from zero
36+
to the length of the sequence.
37+
38+
Of course, this is a smart object that doesn't really create all these sets
39+
in advance, but rather on demand. So you can create a `SelectionSpace` like
40+
this:
41+
42+
>>> selection_space = combi.SelectionSpace(range(10**4))
43+
44+
And take a random selection from it:
45+
46+
>>> selection_space.take_random()
47+
{0, 3, 4, ..., 9996, 9997}
48+
49+
Even though the length of this space is around 10 ** 3010, which is much
50+
bigger than the number of particles in the universe.
51+
'''
2752
def __init__(self, sequence):
2853
self.sequence = \
2954
sequence_tools.ensure_iterable_is_immutable_sequence(sequence)

0 commit comments

Comments
 (0)