CKTIS / Python
itertools.islice
Pobiera leniwie pozycje iteratora.
Wersja: Python 3.14; repository image, production runtime not attested
Składnia
itertools.islice(iterable, stop)
itertools.islice(iterable, start, stop[, step])Pobiera leniwie pozycje iteratora.
Sam stop wybiera początek, a start, stop i dodatni step określają zakres z wyłączonym końcem. Liczbowe granice są nieujemne, None może pozostawić koniec otwarty.
Od 2 przed 8 co 2 daje 2, 4, 6, a równe granice nie dają wyniku.
import itertools as I
it = iter(range(10))
assert list(I.islice(it, 2, 8, 2)) == [2, 4, 6]
assert next(it) == 8 and list(I.islice("abc", 2)) == ["a", "b"]
Przykłady
import itertools as I
print(list(I.islice(I.count(), 2, 8, 2)))
print(list(I.islice(range(3), 3, 3)))
Wynik
[2, 4, 6] []
Od 2 przed 8 co 2 daje 2, 4, 6, a równe granice nie dają wyniku.