注:Python产生的全排列是会含有重复的项的!并且当且仅当输入的列表是升序的,结果才是按字典序的!
from itertools import permutations
a = [1, 2, 4]
perm = permutations(a)
print(type(perm))
''' '''
for item in perm:
print(item)
'''
(1, 2, 4)
(1, 4, 2)
(2, 1, 4)
(2, 4, 1)
(4, 1, 2)
(4, 2, 1)
'''
b = [1, 2, 2, 3]
for item in permutations(b):
print(item)
'''
(1, 2, 2, 3)
(1, 2, 3, 2)
(1, 2, 2, 3)
(1, 2, 3, 2)
(1, 3, 2, 2)
(1, 3, 2, 2)
(2, 1, 2, 3)
(2, 1, 3, 2)
(2, 2, 1, 3)
(2, 2, 3, 1)
(2, 3, 1, 2)
(2, 3, 2, 1)
(2, 1, 2, 3)
(2, 1, 3, 2)
(2, 2, 1, 3)
(2, 2, 3, 1)
(2, 3, 1, 2)
(2, 3, 2, 1)
(3, 1, 2, 2)
(3, 1, 2, 2)
(3, 2, 1, 2)
(3, 2, 2, 1)
(3, 2, 1, 2)
(3, 2, 2, 1)
'''
from collections import deque
a = deque()
a.append(2)
a.append(3)
a.append(4)
a.appendleft(1)
print(a)
''' deque([1, 2, 3, 4]) '''
print(a.pop())
''' 4 '''
print(a.popleft())
''' 1 '''
print(a)
''' deque([2, 3]) '''