排列和组合

import itertools
排列=list(itertools.permutations((1,2,3),2))  #排列有顺序   m!/(m-n)!
组合=list(itertools.combinations((1,2,3),2))  #组合没有顺序  m!/(m-n)!*n
print(排列)
print(组合)

[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
[(1, 2), (1, 3), (2, 3)]

字符串join的用法

str = "-";
seq = ["a", "b", "c"]; # 字符串序列
print(str.join( seq ))

a-b-c

暴力穷举密码

import itertools
mylist=["".join(x) for x in itertools.product("1234",repeat=2)]
print(mylist)
print(len(mylist))

['11', '12', '13', '14', '21', '22', '23', '24', '31', '32', '33', '34', '41', '42', '43', '44']
16