0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

めざせpythonライブラリマスター (24)combi

Posted at

#【ライブラリ説明】
 順列、組み合わせを表示

#【プログラム】

combi.py
# -*- coding: utf-8 -*-

from combi import PermSpace, CombSpace

# 順列
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



# 3つから2つ選ぶ組み合わせ
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')>
'''

#【参考サイト】
 pypi
 github

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?