# 1. 슬라이싱
a = [1,2,3,4]
a = a[1:] + [a[0]]
# a = [2,3,4,1]
# 2. collections.deque
a = deque([1,2,3,4])
a.rotate(1) # a = [4,1,2,3]
a.rotate(-1) # a = [1,2,3,4]
# 3. numpy.roll, -1과 1dms ehdd
a = [1,2,3,4]
np.roll(a, 2) # a = [3,4,1,2]
np.roll(a, -1) # a= [4,1,2,3]
# 4. pandas shift
관련 예제 : 백준 : 14891번: 톱니바퀴
예제 참고 :
단순 슬라이싱
pypy : 메모리: 113248 KB, 시간: 108 ms
python : 메모리 113248 KB, 시간: 120ms
copy import하고 deque를 사용해 rotate를 쓴 것 :
python : 메모리 : 32440KB, 시간 : 112ms