# SortedListWithKey

class `SortedListWithKey`(iterable=None, key=identity, load=1000)

  A `SortedListWithKey` provides most of the same methods as a `list`, but keeps the items in sorted order. To add an element to the SortedListWithKey, use add. To add several elements, use update. To remove an element, use discard, remove, or del L[i].

  An optional iterable provides an initial series of items to populate the `SortedListWithKey`.

  An optional key argument defines a callable that, like the key argument to Python’s sorted function, extracts a comparison key from each element. The default is the identity function.

  An optional load specifies the load-factor of the list. The default load factor of ‘1000’ works well for lists from tens to tens of millions of elements. Good practice is to use a value that is the square or cube root of the list size. With billions of elements, the best load factor depends on your usage. It’s best to leave the load factor at the default until you start benchmarking. See implementation details for more information.

  `SortedListWithKey` implements the MutableSequence Abstract Base Class type.

  `x in L`

    Return True if and only if x is an element in the list.

    Return type: | `bool`

  `del L[i]`

    Remove the element located at index i from the list.

  `del L[i:j]`

    Remove the elements from i to j from the list. Also note that step is supported in slice syntax.

  `L == L2, L != L2, L < L2, L <= L2, L > L2, L >= L2`

    Compare two lists. For full details see Comparisons in the Python language reference.

    Return type: | `bool`

  `L[i]`

    Return the element at position i.

    Return type: | item

  `L[i:j]`

    Return a new `list` containing the elements from i to j. Also note that step is supported in slice syntax.

    Return type: | `list`

  `L *= k`

    Increase the length of the list by a factor of k, by inserting k-1 additional shallow copies of each item in the list.

  `iter`(L)

    Return an iterator over the Sequence.

    Iterating the Sequence while adding or deleting values may raise a RuntimeError or fail to iterate over all entries.

    Return type: | iterator

  `len`(L)

    Return the number of elements in the list.

    Return type: | `int`

  `L * k or k * L`

    Return a new sorted list containing k shallow copies of each item in L.

    Return type: | `SortedListWithKey`

  `L *= k`

    Update L to include k shallow copies of each item in L.

    Return type: | `SortedListWithKey`

  `L + k`

    Return a new sorted list containing all the elements in L and k. Elements in k do not need to be properly ordered with respect to L.

    Return type: | `SortedListWithKey`

  `L += k`

    Update L to include all values in k. Elements in k do not need to be properly ordered with respect to L.

  `reversed`(L)

    Return an iterator to traverse the Sequence in reverse.

    Iterating the Sequence while adding or deleting values may raise a RuntimeError or fail to iterate over all entries.

    Return type: | iterator

  `L[i] = x`

    Replace the item at position i of L with x. Supports slice notation. Raises a `ValueError` if the sort order would be violated.

  `L[i:j] = iterable`

    Replace the items at positions i through j with the contents of iterable. Also note that step is supported in slice syntax.

  `L.``add`(value)

    Add the element value to the list.

  `L.``bisect_left`(value)

    Similar to the `bisect` module in the standard library, this returns an appropriate index to insert value in L. If value is already present in L, the insertion point will be before (to the left of) any existing entries.

    Return type: | `int`

  `L.``bisect`(value)

    Same as bisect_right.

    Return type: | `int`

  `L.``bisect_right`(value)

    Same as bisect_left, but if value is already present in L, the insertion point will be after (to the right of) any existing entries.

    Return type: | `int`

  `L.``bisect_key_left`(key)

    Similar to the `bisect` module in the standard library, this returns an appropriate index to insert a value with a given key. If values with key are already present, the insertion point will be before (to the left of) any existing entries.

    Return type: | `int`

  `L.``bisect_key`(key)

    Same as bisect_key_right.

    Return type: | `int`

  `L.``bisect_key_right`(key)

    Same as bisect_key_left, but if key is already present, the insertion point will be after (to the right of) any existing entries.

    Return type: | `int`

  `L.``count`(value)

    Return the number of occurrences of value in the list.

    Return type: | `int`

  `L.``copy`()

    Return a shallow copy of the sorted list with key.

    Return type: | `SortedListWithKey`

  `L.``discard`(value)

    Remove the first occurrence of value. If value is not a member, does nothing.

  `L.``index`(value[, start[, stop]])

    Return the smallest k such that and . Raises ValueError if value is not present. stop defaults to the end of the list. start defaults to the beginning. Negative indexes are supported, as for slice indices.

    Return type: | `int`

  `L.``pop`([index])

    Remove and return item at index (default last). Raises `IndexError` if list is empty or index is out of range. Negative indexes are supported, as for slice indices.

    Return type: | item

  `L.``remove`(value)

    Remove first occurrence of value. Raises `ValueError` if value is not present.

  `L.``update`(iterable)

    Grow the list by inserting all elements from the iterable.

  `L.``clear`()

    Remove all the elements from the list.

  `L.``append`(value)

    Append the element value to the list. Raises a `ValueError` if the value would violate the sort order.

  `L.``extend`(iterable)

    Extend the list by appending all elements from the iterable. Raises a `ValueError` if the sort order would be violated.

  `L.``insert`(index, value)

    Insert the element value into the list at index. Raises a `ValueError` if the value at index would violate the sort order.

  `L.``islice`(start=None, stop=None, reverse=False)

    Returns an iterator that slices self from start to stop index, inclusive and exclusive respectively.

    When reverse is True, values are yielded from the iterator in reverse order.

    Both start and stop default to None which is automatically inclusive of the beginning and end.

    Return type: | iterator

  `L.``irange`(minimum=None, maximum=None, inclusive=(True, True), reverse=False)

    Create an iterator of values between minimum and maximum.

    inclusive is a pair of booleans that indicates whether the minimum and maximum ought to be included in the range, respectively. The default is (True, True) such that the range is inclusive of both minimum and maximum.

    Both minimum and maximum default to None which is automatically inclusive of the start and end of the list, respectively.

    When reverse is True the values are yielded from the iterator in reverse order; reverse defaults to False.

    Return type: | iterator

  `L.``irange_key`(min_key=None, max_key=None, inclusive=(True, True), reverse=False)

    Create an iterator of values between min_key and max_key.

    inclusive is a pair of booleans that indicates whether the minimum and maximum ought to be included in the range, respectively. The default is (True, True) such that the range is inclusive of both minimum and maximum.

    Both min_key and max_key default to None which is automatically inclusive of the start and end of the list, respectively.

    When reverse is True the values are yielded from the iterator in reverse order; reverse defaults to False.

    Return type: | iterator