Created
August 18, 2021 07:12
-
-
Save ugo-nama-kun/3a2df191c6b10a200a86cdd3588ebfcb to your computer and use it in GitHub Desktop.
Slicable Deque
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From : https://stackoverflow.com/questions/10003143/how-to-slice-a-deque | |
class sliceable_deque(collections.deque): | |
def __getitem__(self, index): | |
try: | |
return collections.deque.__getitem__(self, index) | |
except TypeError: | |
return type(self)(itertools.islice(self, index.start, | |
index.stop, index.step)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We cannot do this:
because we get an error as in the link. Then now we can do this