MCPcopy Index your code
hub / github.com/RustPython/RustPython / islice

Method islice

Lib/test/test_itertools.py:1756–1774  ·  view source on GitHub ↗
(iterable, *args)

Source from the content-addressed store, hash-verified

1754
1755 @staticmethod
1756 def islice(iterable, *args):
1757 # islice('ABCDEFG', 2) → A B
1758 # islice('ABCDEFG', 2, 4) → C D
1759 # islice('ABCDEFG', 2, None) → C D E F G
1760 # islice('ABCDEFG', 0, None, 2) → A C E G
1761
1762 s = slice(*args)
1763 start = 0 if s.start is None else s.start
1764 stop = s.stop
1765 step = 1 if s.step is None else s.step
1766 if start < 0 or (stop is not None and stop < 0) or step <= 0:
1767 raise ValueError
1768
1769 indices = count() if stop is None else range(max(start, stop))
1770 next_i = start
1771 for i, element in zip(indices, iterable):
1772 if i == next_i:
1773 yield element
1774 next_i += step
1775
1776 def test_islice_recipe(self):
1777 self.assertEqual(list(self.islice('ABCDEFG', 2)), list('AB'))

Callers 9

test_islice_recipeMethod · 0.95
_get_code_positionFunction · 0.80
_get_code_positionFunction · 0.80
_get_sendmsg_bufferMethod · 0.80
make_namesMethod · 0.80
_parentsFunction · 0.80
_get_tasksMethod · 0.80

Calls 3

sliceClass · 0.85
countFunction · 0.85
maxFunction · 0.85

Tested by

no test coverage detected