ATLAS Offline Software
Functions | Variables
python.combo Namespace Reference

Functions

def all_combinations (items, n)
 
def combinations (items, n)
 
def selections (items, n)
 
def permutations (items)
 

Variables

string __version__ = "1.0"
 
dictionary __test__ = {}
 

Function Documentation

◆ all_combinations()

def python.combo.all_combinations (   items,
  n 
)
Return all subsequences of length n from items.
Differences in ordering are considered significant.
For example, all_combinations([1,2,3],2) will yield both [1,2] and [2,1].

>>> for c in all_combinations(['l','o','v','e'],2):
...   print (''.join(c))
lo
lv
le
ol
ov
oe
vl
vo
ve
el
eo
ev

Definition at line 58 of file combo.py.

58 def all_combinations(items, n):
59  """Return all subsequences of length n from items.
60 Differences in ordering are considered significant.
61 For example, all_combinations([1,2,3],2) will yield both [1,2] and [2,1].
62 
63 >>> for c in all_combinations(['l','o','v','e'],2):
64 ... print (''.join(c))
65 lo
66 lv
67 le
68 ol
69 ov
70 oe
71 vl
72 vo
73 ve
74 el
75 eo
76 ev
77 """
78  if n==0:
79  yield []
80  else:
81  for i in range(len(items)):
82  for cc in all_combinations(items[:i]+items[i+1:],n-1):
83  yield [items[i]]+cc
84 

◆ combinations()

def python.combo.combinations (   items,
  n 
)
Yields all unique subsequences of length n from items.

>>> for uc in combinations(['l','o','v','e'],2):
...   print (''.join(uc))
lo
lv
le
ov
oe
ve

Definition at line 85 of file combo.py.

85 def combinations(items, n):
86  """Yields all unique subsequences of length n from items.
87 
88 >>> for uc in combinations(['l','o','v','e'],2):
89 ... print (''.join(uc))
90 lo
91 lv
92 le
93 ov
94 oe
95 ve
96 """
97  if n==0:
98  yield []
99  else:
100  for i in range(len(items)):
101  for cc in combinations(items[i+1:],n-1):
102  yield [items[i]]+cc
103 

◆ permutations()

def python.combo.permutations (   items)
Yields all permutations of items.
Equivalent to all_combinations(items,len(items)).

>>> for p in permutations(['l','o','v','e']):
...   print (''.join(p))
love
loev
lvoe
lveo
leov
levo
olve
olev
ovle
ovel
oelv
oevl
vloe
vleo
vole
voel
velo
veol
elov
elvo
eolv
eovl
evlo
evol

Definition at line 134 of file combo.py.

134 def permutations(items):
135  """ Yields all permutations of items.
136 Equivalent to all_combinations(items,len(items)).
137 
138 >>> for p in permutations(['l','o','v','e']):
139 ... print (''.join(p))
140 love
141 loev
142 lvoe
143 lveo
144 leov
145 levo
146 olve
147 olev
148 ovle
149 ovel
150 oelv
151 oevl
152 vloe
153 vleo
154 vole
155 voel
156 velo
157 veol
158 elov
159 elvo
160 eolv
161 eovl
162 evlo
163 evol
164 """
165  return all_combinations(items, len(items))
166 
167 

◆ selections()

def python.combo.selections (   items,
  n 
)
Returns all possible ways of picking n items from
items, where any given item may be picked multiple times.

>>> for s in selections(['l','o','v','e'],2):
...   print (''.join(s))
ll
lo
lv
le
ol
oo
ov
oe
vl
vo
vv
ve
el
eo
ev
ee

Definition at line 104 of file combo.py.

104 def selections(items, n):
105  """Returns all possible ways of picking n items from
106 items, where any given item may be picked multiple times.
107 
108 >>> for s in selections(['l','o','v','e'],2):
109 ... print (''.join(s))
110 ll
111 lo
112 lv
113 le
114 ol
115 oo
116 ov
117 oe
118 vl
119 vo
120 vv
121 ve
122 el
123 eo
124 ev
125 ee
126 """
127  if n==0:
128  yield []
129  else:
130  for i in range(len(items)):
131  for ss in selections(items, n-1):
132  yield [items[i]]+ss
133 

Variable Documentation

◆ __test__

dictionary python.combo.__test__ = {}
private

Definition at line 168 of file combo.py.

◆ __version__

string python.combo.__version__ = "1.0"
private

Definition at line 42 of file combo.py.

python.combo.all_combinations
def all_combinations(items, n)
Definition: combo.py:58
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.combo.permutations
def permutations(items)
Definition: combo.py:134
python.combo.selections
def selections(items, n)
Definition: combo.py:104
python.combo.combinations
def combinations(items, n)
Definition: combo.py:85