Created
July 21, 2020 04:16
-
-
Save hyrious/07992adc0e4d2d03417459a21d305fac to your computer and use it in GitHub Desktop.
wrap islice
This file contains 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
import sys | |
from itertools import islice | |
from typing import Iterator, List, Any | |
class Slicable: | |
def __init__(self, a: Iterator): | |
self.a = a | |
def __getitem__(self, s: 'slice') -> List[Any]: | |
return list(islice(self.a, s.start, s.stop, s.step)) | |
def fib(): | |
a, b = 0, 1 | |
while True: | |
a, b = a + b, a | |
yield a | |
a = Slicable(fib()) | |
print(a[:10:2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment