Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/sortedcontainers/__init__.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1"""Sorted Containers -- Sorted List, Sorted Dict, Sorted Set 

2 

3Sorted Containers is an Apache2 licensed containers library, written in 

4pure-Python, and fast as C-extensions. 

5 

6Python's standard library is great until you need a sorted collections 

7type. Many will attest that you can get really far without one, but the moment 

8you **really need** a sorted list, dict, or set, you're faced with a dozen 

9different implementations, most using C-extensions without great documentation 

10and benchmarking. 

11 

12In Python, we can do better. And we can do it in pure-Python! 

13 

14:: 

15 

16 >>> from sortedcontainers import SortedList 

17 >>> sl = SortedList(['e', 'a', 'c', 'd', 'b']) 

18 >>> sl 

19 SortedList(['a', 'b', 'c', 'd', 'e']) 

20 >>> sl *= 1000000 

21 >>> sl.count('c') 

22 1000000 

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') 

36 2 

37 

38Sorted Containers takes all of the work out of Python sorted types - making 

39your deployment and use of Python easy. There's no need to install a C compiler 

40or pre-build and distribute custom extensions. Performance is a feature and 

41testing has 100% coverage with unit tests and hours of stress. 

42 

43:copyright: (c) 2014-2019 by Grant Jenks. 

44:license: Apache 2.0, see LICENSE for more details. 

45 

46""" 

47 

48 

49from .sortedlist import SortedList, SortedKeyList, SortedListWithKey 

50from .sortedset import SortedSet 

51from .sorteddict import ( 

52 SortedDict, 

53 SortedKeysView, 

54 SortedItemsView, 

55 SortedValuesView, 

56) 

57 

58__all__ = [ 

59 'SortedList', 

60 'SortedKeyList', 

61 'SortedListWithKey', 

62 'SortedDict', 

63 'SortedKeysView', 

64 'SortedItemsView', 

65 'SortedValuesView', 

66 'SortedSet', 

67] 

68 

69__title__ = 'sortedcontainers' 

70__version__ = '2.4.0' 

71__build__ = 0x020400 

72__author__ = 'Grant Jenks' 

73__license__ = 'Apache 2.0' 

74__copyright__ = '2014-2019, Grant Jenks'