Pythonライブラリ
4488 ワード
コンポジット
整列
from itertools import permutations
print(list(permutations([1,2,3,4], 2)))
print(list(permutations([1,2,3,1], 2)))
# result1
# [(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]
# result2
# [(1, 2), (1, 3), (1, 1), (2, 1), (2, 3), (2, 1), (3, 1), (3, 2), (3, 1), (1, 1), (1, 2), (1, 3)]
コンポジットfrom itertools import combinations
print(list(combinations([1,2,3,4], 2)))
print(list(combinations([1,2,3,1], 2)))
# result1
# [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
# result2
# [(1, 2), (1, 3), (1, 1), (2, 3), (2, 1), (3, 1)]
カウンター台
from collections import counter
키,값으로 값에 키에 대한 횟수로 바꿔준다
Counter('hello world') # Counter({'l': 3, 'o': 2, 'h': 1, 'e': 1, ' ': 1, 'w': 1, 'r': 1, 'd': 1})
Reference
この問題について(Pythonライブラリ), 我々は、より多くの情報をここで見つけました https://velog.io/@refindmysapporo/파이썬-라이브러리テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol