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.
| 655 | |
| 656 | |
| 657 | class 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 | |
| 706 | class SortedItemsView(ItemsView, Sequence): |