1. deque()에서는 rotate()가 가능하다.
from collections import deque
A = deque([1,2,3,4,5])
A.rotate(-1)
A #deque([5, 1, 2, 3, 4])
2. deque()를 deepcopy()해도 rotate()가 가능하다.
from collections import deque
from copy import deepcopy
A = deque([1,2,3,4,5])
A.rotate(1)
B = deepcopy(A)
B #deque([5, 1, 2, 3, 4])
3. dict()의 value가 deque()여도 rotate()가 가능하다.
A = {0 : deque([1,2,3,4,5]),
1 : deque([1,2,3,4,5]),
2 : deque([1,2,3,4,5]),
3 : deque([1,2,3,4,5])}
A[1].rotate(1)
A
"""
{0: deque([1, 2, 3, 4, 5]),
1: deque([5, 1, 2, 3, 4]),
2: deque([1, 2, 3, 4, 5]),
3: deque([1, 2, 3, 4, 5])}
"""
4. value가 deque()인 dict()를 deepcopy()해도 rotate()가 가능하다.
A = {0 : deque([1,2,3,4,5]),
1 : deque([1,2,3,4,5]),
2 : deque([1,2,3,4,5]),
3 : deque([1,2,3,4,5])}
B = deepcopy(A)
B[1].rotate(1)
B
"""
{0: deque([1, 2, 3, 4, 5]),
1: deque([5, 1, 2, 3, 4]),
2: deque([1, 2, 3, 4, 5]),
3: deque([1, 2, 3, 4, 5])}
"""
5. 그러나 defaultdict()의 value가 deque()면 rotate()가 되지 않는다.
from collections import defaultdict, deque
A = defaultdict(list)
for i in range(1, 6) :
A[1].append(i)
print(A) #defaultdict(list, {1: [1, 2, 3, 4, 5]}
A[1].rotate(1)
A
"""
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-de1de4ae888c> in <cell line: 10>()
8 print(A) #defaultdict(list, {1: [1, 2, 3, 4, 5]}
9
---> 10 A[1].rotate(1)
11 A #defaultdict(list, {0: deque([[1, 2, 3, 4, 5]])})
AttributeError: 'list' object has no attribute 'rotate'
"""