MCPcopy Create free account
hub / github.com/grantjenks/python-sortedcontainers / islice

Method islice

sortedcontainers/sortedlist.py:962–1005  ·  view source on GitHub ↗

Return an iterator that slices sorted list from `start` to `stop`. The `start` and `stop` index are treated inclusive and exclusive, respectively. Both `start` and `stop` default to `None` which is automatically inclusive of the beginning and end of the sorted list.

(self, start=None, stop=None, reverse=False)

Source from the content-addressed store, hash-verified

960
961
962 def islice(self, start=None, stop=None, reverse=False):
963 """Return an iterator that slices sorted list from `start` to `stop`.
964
965 The `start` and `stop` index are treated inclusive and exclusive,
966 respectively.
967
968 Both `start` and `stop` default to `None` which is automatically
969 inclusive of the beginning and end of the sorted list.
970
971 When `reverse` is `True` the values are yielded from the iterator in
972 reverse order; `reverse` defaults to `False`.
973
974 >>> sl = SortedList('abcdefghij')
975 >>> it = sl.islice(2, 6)
976 >>> list(it)
977 ['c', 'd', 'e', 'f']
978
979 :param int start: start index (inclusive)
980 :param int stop: stop index (exclusive)
981 :param bool reverse: yield values in reverse order
982 :return: iterator
983
984 """
985 _len = self._len
986
987 if not _len:
988 return iter(())
989
990 start, stop, _ = slice(start, stop).indices(self._len)
991
992 if start >= stop:
993 return iter(())
994
995 _pos = self._pos
996
997 min_pos, min_idx = _pos(start)
998
999 if stop == _len:
1000 max_pos = len(self._lists) - 1
1001 max_idx = len(self._lists[-1])
1002 else:
1003 max_pos, max_idx = _pos(stop)
1004
1005 return self._islice(min_pos, min_idx, max_pos, max_idx, reverse)
1006
1007
1008 def _islice(self, min_pos, min_idx, max_pos, max_idx, reverse):

Callers 6

test_isliceFunction · 0.95
test_isliceFunction · 0.80
stress_isliceFunction · 0.80
test_isliceFunction · 0.80
test_isliceFunction · 0.80
test_isliceFunction · 0.80

Calls 2

_isliceMethod · 0.95
iterFunction · 0.50

Tested by 6

test_isliceFunction · 0.76
test_isliceFunction · 0.64
stress_isliceFunction · 0.64
test_isliceFunction · 0.64
test_isliceFunction · 0.64
test_isliceFunction · 0.64