Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created July 21, 2020 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrious/07992adc0e4d2d03417459a21d305fac to your computer and use it in GitHub Desktop.
Save hyrious/07992adc0e4d2d03417459a21d305fac to your computer and use it in GitHub Desktop.
wrap islice
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