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

Class SortedKeysView

sortedcontainers/sorteddict.py:657–703  ·  view source on GitHub ↗

Sorted keys view is a dynamic view of the sorted dict's keys. When the sorted dict's keys change, the view reflects those changes. The keys view implements the set and sequence abstract base classes.

Source from the content-addressed store, hash-verified

655
656
657class SortedKeysView(KeysView, Sequence):
658 """Sorted keys view is a dynamic view of the sorted dict's keys.
659
660 When the sorted dict's keys change, the view reflects those changes.
661
662 The keys view implements the set and sequence abstract base classes.
663
664 """
665 __slots__ = ()
666
667
668 @classmethod
669 def _from_iterable(cls, it):
670 return SortedSet(it)
671
672
673 def __getitem__(self, index):
674 """Lookup key at `index` in sorted keys views.
675
676 ``skv.__getitem__(index)`` <==> ``skv[index]``
677
678 Supports slicing.
679
680 Runtime complexity: `O(log(n))` -- approximate.
681
682 >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
683 >>> skv = sd.keys()
684 >>> skv[0]
685 'a'
686 >>> skv[-1]
687 'c'
688 >>> skv[:]
689 ['a', 'b', 'c']
690 >>> skv[100]
691 Traceback (most recent call last):
692 ...
693 IndexError: list index out of range
694
695 :param index: integer or slice for indexing
696 :return: key or list of keys
697 :raises IndexError: if index out of range
698
699 """
700 return self._mapping._list[index]
701
702
703 __delitem__ = _view_delitem
704
705
706class SortedItemsView(ItemsView, Sequence):

Callers 2

ilocMethod · 0.85
keysMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected