As you know, collections.deque
does not support regular slicing in Python, and so I have to use itertools.islice
instead.
However, I know that index access to elements in collections.deque
are not constant time in general (they are linear in terms of how far away the index is from the head/tail).
If I want to get the last N elements of a deque
. What is the time complexity of itertools.islice(deque, len(deque) - N, len(deque))
? How is itertools.islice
implemented?