d = deque('abcdefg')
# append, add a new entry to the right side
d.append('j') # deque(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'j'])
# appendleft, add a new entry to the left side
d.appendleft('f') # deque(['f', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'j'])
# pop
print(d.pop()) # j, return and remove the rightmost item
# popleft
print(d.popleft()) # f, return and remove the leftmost item
print(d) # deque(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
print(d[0]) # a, peek at leftmost item
print(d[-1]) # g, peek at rightmost item
# extend, add multiple elements at once
d.extend(['Hello', 'World']) # deque(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'Hello', 'World'])
# rotate
d.rotate(3) # deque(['g', 'Hello', 'World', 'a', 'b', 'c', 'd', 'e', 'f']), right rotation
d.rotate(-2) # deque(['World', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'Hello']), left rotation
# clear, empty the deque
d.clear()