Sorted values view is a dynamic view of the sorted dict's values. When the sorted dict's values change, the view reflects those changes. The values view implements the sequence abstract base class.
| 761 | |
| 762 | |
| 763 | class SortedValuesView(ValuesView, Sequence): |
| 764 | """Sorted values view is a dynamic view of the sorted dict's values. |
| 765 | |
| 766 | When the sorted dict's values change, the view reflects those changes. |
| 767 | |
| 768 | The values view implements the sequence abstract base class. |
| 769 | |
| 770 | """ |
| 771 | __slots__ = () |
| 772 | |
| 773 | |
| 774 | def __getitem__(self, index): |
| 775 | """Lookup value at `index` in sorted values view. |
| 776 | |
| 777 | ``siv.__getitem__(index)`` <==> ``siv[index]`` |
| 778 | |
| 779 | Supports slicing. |
| 780 | |
| 781 | Runtime complexity: `O(log(n))` -- approximate. |
| 782 | |
| 783 | >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3}) |
| 784 | >>> svv = sd.values() |
| 785 | >>> svv[0] |
| 786 | 1 |
| 787 | >>> svv[-1] |
| 788 | 3 |
| 789 | >>> svv[:] |
| 790 | [1, 2, 3] |
| 791 | >>> svv[100] |
| 792 | Traceback (most recent call last): |
| 793 | ... |
| 794 | IndexError: list index out of range |
| 795 | |
| 796 | :param index: integer or slice for indexing |
| 797 | :return: value or list of values |
| 798 | :raises IndexError: if index out of range |
| 799 | |
| 800 | """ |
| 801 | _mapping = self._mapping |
| 802 | _mapping_list = _mapping._list |
| 803 | |
| 804 | if isinstance(index, slice): |
| 805 | keys = _mapping_list[index] |
| 806 | return [_mapping[key] for key in keys] |
| 807 | |
| 808 | key = _mapping_list[index] |
| 809 | return _mapping[key] |
| 810 | |
| 811 | |
| 812 | __delitem__ = _view_delitem |