|
1 |
| -"""Sorted Container Types: SortedList, SortedDict, SortedSet |
| 1 | +"""Sorted Containers -- Sorted List, Sorted Dict, Sorted Set |
2 | 2 |
|
3 |
| -SortedContainers is an Apache2 licensed containers library, written in |
| 3 | +Sorted Containers is an Apache2 licensed containers library, written in |
4 | 4 | pure-Python, and fast as C-extensions.
|
5 | 5 |
|
6 |
| -
|
7 | 6 | Python's standard library is great until you need a sorted collections
|
8 | 7 | type. Many will attest that you can get really far without one, but the moment
|
9 | 8 | you **really need** a sorted list, dict, or set, you're faced with a dozen
|
|
14 | 13 |
|
15 | 14 | ::
|
16 | 15 |
|
17 |
| - >>> from sortedcontainers import SortedList, SortedDict, SortedSet |
18 |
| - >>> sl = SortedList(range(10000000)) |
19 |
| - >>> 1234567 in sl |
20 |
| - True |
21 |
| - >>> sl[7654321] |
22 |
| - 7654321 |
23 |
| - >>> sl.add(1234567) |
24 |
| - >>> sl.count(1234567) |
| 16 | + >>> from sortedcontainers import SortedList |
| 17 | + >>> sl = SortedList(['e', 'a', 'c', 'd', 'b']) |
| 18 | + >>> sl |
| 19 | + SortedList(['a', 'b', 'c', 'd', 'e']) |
| 20 | + >>> sl *= 10_000_000 |
| 21 | + >>> sl.count('c') |
| 22 | + 10000000 |
| 23 | + >>> sl[-3:] |
| 24 | + ['e', 'e', 'e'] |
| 25 | + >>> from sortedcontainers import SortedDict |
| 26 | + >>> sd = SortedDict({'c': 3, 'a': 1, 'b': 2}) |
| 27 | + >>> sd |
| 28 | + SortedDict({'a': 1, 'b': 2, 'c': 3}) |
| 29 | + >>> sd.popitem(index=-1) |
| 30 | + ('c', 3) |
| 31 | + >>> from sortedcontainers import SortedSet |
| 32 | + >>> ss = SortedSet('abracadabra') |
| 33 | + >>> ss |
| 34 | + SortedSet(['a', 'b', 'c', 'd', 'r']) |
| 35 | + >>> ss.bisect_left('c') |
25 | 36 | 2
|
26 |
| - >>> sl *= 3 |
27 |
| - >>> len(sl) |
28 |
| - 30000003 |
29 | 37 |
|
30 |
| -SortedContainers takes all of the work out of Python sorted types - making your |
31 |
| -deployment and use of Python easy. There's no need to install a C compiler or |
32 |
| -pre-build and distribute custom extensions. Performance is a feature and |
| 38 | +Sorted Containers takes all of the work out of Python sorted types - making |
| 39 | +your deployment and use of Python easy. There's no need to install a C compiler |
| 40 | +or pre-build and distribute custom extensions. Performance is a feature and |
33 | 41 | testing has 100% coverage with unit tests and hours of stress.
|
34 | 42 |
|
35 | 43 | :copyright: (c) 2014-2018 by Grant Jenks.
|
|
0 commit comments