Sequenzen und Kombinationen anzeigen
combi.py
# -*- coding: utf-8 -*-
from combi import PermSpace, CombSpace
#Permutation
perm_space = PermSpace('meow')
print len(perm_space)
# 24
for i in xrange(len(perm_space)):
print perm_space[i]
'''
<Perm: ('m', 'e', 'o', 'w')>
<Perm: ('m', 'e', 'w', 'o')>
<Perm: ('m', 'o', 'e', 'w')>
<Perm: ('m', 'o', 'w', 'e')>
<Perm: ('m', 'w', 'e', 'o')>
<Perm: ('m', 'w', 'o', 'e')>
<Perm: ('e', 'm', 'o', 'w')>
<Perm: ('e', 'm', 'w', 'o')>
<Perm: ('e', 'o', 'm', 'w')>
<Perm: ('e', 'o', 'w', 'm')>
<Perm: ('e', 'w', 'm', 'o')>
<Perm: ('e', 'w', 'o', 'm')>
<Perm: ('o', 'm', 'e', 'w')>
<Perm: ('o', 'm', 'w', 'e')>
<Perm: ('o', 'e', 'm', 'w')>
<Perm: ('o', 'e', 'w', 'm')>
<Perm: ('o', 'w', 'm', 'e')>
<Perm: ('o', 'w', 'e', 'm')>
<Perm: ('w', 'm', 'e', 'o')>
<Perm: ('w', 'm', 'o', 'e')>
<Perm: ('w', 'e', 'm', 'o')>
<Perm: ('w', 'e', 'o', 'm')>
<Perm: ('w', 'o', 'm', 'e')>
<Perm: ('w', 'o', 'e', 'm')>
'''
print perm_space.index('mowe')
# 3
#Kombination zur Auswahl von 2 aus 3
comb_space = CombSpace(('vanilla', 'chocolate', 'strawberry'), 2)
print len(comb_space)
# 3
for i in xrange(len(comb_space)):
print comb_space[i]
'''
<Comb, n_elements=2: ('vanilla', 'chocolate')>
<Comb, n_elements=2: ('vanilla', 'strawberry')>
<Comb, n_elements=2: ('chocolate', 'strawberry')>
'''
Recommended Posts