A sortedset provides the same methods as a set. Additionally, a sortedset: maintains its items in sorted order, allowing the sortedset to be indexed.
An optional iterable provides an initial series of items to populate the sortedset.
key specifies a function of one argument that is used to extract a comparison key from each set element: key=str.lower. The default value is None (compare the elements directly). The key function must always return the same key for an item or the results are unpredictable.
Unlike a set, a sortedset does not require items to be hashable.
A sortedset can be used as an order statistic tree (Cormen et al., Introduction to Algorithms, ch. 14).
Returns True if and only if x is an element in the set.
Requires total operations or comparisons.
Return type: | bool |
---|
Removes the element located at index i from the set.
Requires operations and no comparisons.
Removes the elements from i to j from the set.
Requires operations and no comparisons.
Test whether the set is a proper subset of S2, that is, S <= S2 and S != other.
In the worst case, requires operations multiplied by the cost of S2‘s in operation.
Return type: | bool |
---|
Test whether the set is a proper superset of S2, that is, S >= S2 and S != S2.
In the worst case, requires operations or comparisons, where m is the size of S2 and n is the size of S.
Return type: | bool |
---|
Returns the element at position i.
Requires operations in the worst case but only operations if the set’s size has not been changed recently. Requires no comparisons in any case.
(Cormen et al. call this operation “SELECT”.)
Return type: | item |
---|
Returns a new sortedset containing the elements from i to j.
Requires operations and no comparisons.
Return type: | sortedset |
---|
Increase the length of the set by a factor of k, by inserting k-1 additional shallow copies of each item in the set.
Requires operations and no comparisons.
Creates an iterator over the set.
Requires operations to create the iterator. Each element from the iterator requires operations to retrieve, or operations to iterate over the entire set.
Return type: | iterator |
---|
Returns the number of elements in the set.
Requires operations.
Return type: | int |
---|
Returns a new sorted set containing k shallow copies of each item in S.
Requires operations and no comparisons.
Return type: | sortedset |
---|
Creates an iterator to traverse the set in reverse.
Requires operations to create the iterator. Each element from the iterator requires operations to retrieve, or operations to iterate over the entire set. Requires no comparisons in any case.
Return type: | iterator |
---|
Add the element value to the set.
Requires total operations or comparisons.
Similarly 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.
Requires total operations or comparisons.
Same as bisect_left.
Same thing as bisect_left, but if value is already present in L, the insertion point will be after (to the right of) any existing entries.
Remove all elements from the set.
Requires total operations and no comparisons in the worst case.
Creates a shallow copy of the set.
Requires total operations and no comparisons.
Return type: | sortedset |
---|
Returns the number of occurrences of value in the set.
Requires operations and comparisons in the worst case.
Return type: | int |
---|
Return a new set with elements in the set that are not in the others.
In the worst case, requires operations and comparisons, where m is the combined size of all the other sets and n is the size of S.
Return type: | sortedset |
---|
Update the set, removing elements found in keeping only elements found in any of the others.
In the worst case, requires operations and comparisons, where m is the combined size of all the other sets and n is the initial size of S.
Removes the first occurrence of value. If value is not a member, does nothing.
In the worst case, requires operations and comparisons.
Returns the smallest k such that and . Raises ValueError if value is not present. stop defaults to the end of the set. start defaults to the beginning. Negative indexes are supported, as for slice indices.
In the worst case, requires operations and comparisons, where m is stop - start.
(Cormen et al. call this operation “RANK”.)
Return type: | int |
---|
Return a new set with elements common to the set and all others.
In the worst case, requires operations and comparisons, where m is the combined size of all the other sets and n is the size of S.
Return type: | sortedset |
---|
Update the set, keeping only elements found in it and all others.
In the worst case, requires operations and comparisons, where m is the combined size of all the other sets and n is the initial size of S.
Return True if the set has no elements in common with S2. Sets are disjoint if and only if their intersection is the empty set.
Return type: | bool |
---|
Test whether every element in the set is in S2
In the worst case, requires operations multiplied by the cost of S2‘s in operation.
Return type: | bool |
---|
Test whether every element in S2 is in the set.
In the worst case, requires operations or comparisons, where m is the size of S2 and n is the size of S.
Return type: | bool |
---|
Return a new set with element in either set but not both.
In the worst case, requires operations and comparisons, where m is the size of S2 and n is the size of S.
Return type: | sortedset |
---|
Update the set, keeping only elements found in either set, but not in both.
In the worst case, requires operations and comparisons, where m is the size of S2 and n is the initial size of S.
Removes and return item at index (default last). Raises IndexError if set is empty or index is out of range. Negative indexes are supported, as for slice indices.
Requires operations and no comparisons.
Return type: | item |
---|
Remove first occurrence of value. Raises ValueError if value is not present.
In the worst case, requires operations and comparisons.
Return a new sortedset with elements from the set and all others. The new sortedset will be sorted according to the key of the leftmost set.
Requires operations or comparisons, where m is the total size of the other sets and n is the size of S.
Return type: | sortedset |
---|
Update the set, adding elements from all others.
In the worst case, requires operations and comparisons, where m is the combined size of all the other sets and n is the initial size of S.