![]() |
ノート/Python/itertoolshttp://pepper.is.sci.toho-u.ac.jp/pepper/index.php?%A5%CE%A1%BC%A5%C8%2FPython%2Fitertools |
![]() |
ノート/Python
訪問者数 1335 最終更新 2013-05-10 (金) 11:01:20
itertoolsパッケージは組合せとかを生成してくれる。
参考
import itertools for c in itertools.combinations([1,2,3,4,5],2): print(c)
実際使ってみた
dict = {"yamada":75, "endou":82} print dict.keys() > ['yamada', 'endou'] print dict.values() > [75, 82] print dict.items() > [('yamada', 75), ('endou', 82)] list = dict.items() list > [('yamada', 75), ('endou', 82)] list.append(('tanaka', 65)) list > [('yamada', 75), ('endou', 82), ('tanaka', 65)] import itertools for c in itertools.combinations(list,2): print(c) > (('yamada', 75), ('endou', 82)) > (('yamada', 75), ('tanaka', 65)) > (('endou', 82), ('tanaka', 65))
というわけで、何も考えずに組合せができてしまう。