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 57 of file combo.py.

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

◆ 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 84 of file combo.py.

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

◆ 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 133 of file combo.py.

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

◆ 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 103 of file combo.py.

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

Variable Documentation

◆ __test__

dictionary python.combo.__test__ = {}
private

Definition at line 167 of file combo.py.

◆ __version__

string python.combo.__version__ = "1.0"
private

Definition at line 41 of file combo.py.

python.combo.all_combinations
def all_combinations(items, n)
Definition: combo.py:57
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.combo.permutations
def permutations(items)
Definition: combo.py:133
python.combo.selections
def selections(items, n)
Definition: combo.py:103
python.combo.combinations
def combinations(items, n)
Definition: combo.py:84