@@ -359,23 +359,23 @@ def __ror__(self, other):
359
359
def namedtuple (typename , field_names , * , rename = False , defaults = None , module = None ):
360
360
"""Returns a new subclass of tuple with named fields.
361
361
362
- >>> Point = namedtuple(' Point' , ['x', 'y' ])
363
- >>> Point.__doc__ # docstring for the new class
362
+ >>> Point = namedtuple(" Point" , ["x", "y" ])
363
+ >>> Point.__doc__ # docstring for the new class
364
364
'Point(x, y)'
365
- >>> p = Point(11, y=22) # instantiate with positional args or keywords
366
- >>> p[0] + p[1] # indexable like a plain tuple
365
+ >>> p = Point(11, y=22) # instantiate with positional args or keywords
366
+ >>> p[0] + p[1] # indexable like a plain tuple
367
367
33
368
- >>> x, y = p # unpack like a regular tuple
368
+ >>> x, y = p # unpack like a regular tuple
369
369
>>> x, y
370
370
(11, 22)
371
- >>> p.x + p.y # fields also accessible by name
371
+ >>> p.x + p.y # fields also accessible by name
372
372
33
373
- >>> d = p._asdict() # convert to a dictionary
374
- >>> d['x' ]
373
+ >>> d = p._asdict() # convert to a dictionary
374
+ >>> d["x" ]
375
375
11
376
- >>> Point(**d) # convert from a dictionary
376
+ >>> Point(**d) # convert from a dictionary
377
377
Point(x=11, y=22)
378
- >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
378
+ >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
379
379
Point(x=100, y=22)
380
380
381
381
"""
@@ -562,42 +562,42 @@ class Counter(dict):
562
562
or multiset. Elements are stored as dictionary keys and their counts
563
563
are stored as dictionary values.
564
564
565
- >>> c = Counter(' abcdeabcdabcaba' ) # count elements from a string
565
+ >>> c = Counter(" abcdeabcdabcaba" ) # count elements from a string
566
566
567
- >>> c.most_common(3) # three most common elements
567
+ >>> c.most_common(3) # three most common elements
568
568
[('a', 5), ('b', 4), ('c', 3)]
569
- >>> sorted(c) # list all unique elements
569
+ >>> sorted(c) # list all unique elements
570
570
['a', 'b', 'c', 'd', 'e']
571
- >>> '' .join(sorted(c.elements())) # list elements with repetitions
571
+ >>> "" .join(sorted(c.elements())) # list elements with repetitions
572
572
'aaaaabbbbcccdde'
573
- >>> sum(c.values()) # total of all counts
573
+ >>> sum(c.values()) # total of all counts
574
574
15
575
575
576
- >>> c['a'] # count of letter 'a'
576
+ >>> c["a"] # count of letter 'a'
577
577
5
578
- >>> for elem in ' shazam': # update counts from an iterable
579
- ... c[elem] += 1 # by adding 1 to each element's count
580
- >>> c['a'] # now there are seven 'a'
578
+ >>> for elem in " shazam": # update counts from an iterable
579
+ ... c[elem] += 1 # by adding 1 to each element's count
580
+ >>> c["a"] # now there are seven 'a'
581
581
7
582
- >>> del c['b'] # remove all 'b'
583
- >>> c['b'] # now there are zero 'b'
582
+ >>> del c["b"] # remove all 'b'
583
+ >>> c["b"] # now there are zero 'b'
584
584
0
585
585
586
- >>> d = Counter(' simsalabim') # make another counter
587
- >>> c.update(d) # add in the second counter
588
- >>> c['a'] # now there are nine 'a'
586
+ >>> d = Counter(" simsalabim") # make another counter
587
+ >>> c.update(d) # add in the second counter
588
+ >>> c["a"] # now there are nine 'a'
589
589
9
590
590
591
- >>> c.clear() # empty the counter
591
+ >>> c.clear() # empty the counter
592
592
>>> c
593
593
Counter()
594
594
595
595
Note: If a count is set to zero or reduced to zero, it will remain
596
596
in the counter until the entry is deleted or the counter is cleared:
597
597
598
- >>> c = Counter(' aaabbc' )
599
- >>> c['b' ] -= 2 # reduce the count of 'b' by two
600
- >>> c.most_common() # 'b' is still in, but its count is zero
598
+ >>> c = Counter(" aaabbc" )
599
+ >>> c["b" ] -= 2 # reduce the count of 'b' by two
600
+ >>> c.most_common() # 'b' is still in, but its count is zero
601
601
[('a', 3), ('c', 1), ('b', 0)]
602
602
603
603
"""
@@ -614,10 +614,10 @@ def __init__(self, iterable=None, /, **kwds):
614
614
from an input iterable. Or, initialize the count from another mapping
615
615
of elements to their counts.
616
616
617
- >>> c = Counter() # a new, empty counter
618
- >>> c = Counter(' gallahad') # a new counter from an iterable
619
- >>> c = Counter({'a' : 4, 'b' : 2}) # a new counter from a mapping
620
- >>> c = Counter(a=4, b=2) # a new counter from keyword args
617
+ >>> c = Counter() # a new, empty counter
618
+ >>> c = Counter(" gallahad") # a new counter from an iterable
619
+ >>> c = Counter({"a" : 4, "b" : 2}) # a new counter from a mapping
620
+ >>> c = Counter(a=4, b=2) # a new counter from keyword args
621
621
622
622
"""
623
623
super ().__init__ ()
@@ -636,7 +636,7 @@ def most_common(self, n=None):
636
636
"""List the n most common elements and their counts from the most
637
637
common to the least. If n is None, then list all element counts.
638
638
639
- >>> Counter(' abracadabra' ).most_common(3)
639
+ >>> Counter(" abracadabra" ).most_common(3)
640
640
[('a', 5), ('b', 2), ('r', 2)]
641
641
642
642
"""
@@ -652,7 +652,7 @@ def most_common(self, n=None):
652
652
def elements (self ):
653
653
"""Iterator over elements repeating each as many times as its count.
654
654
655
- >>> c = Counter(' ABCABC' )
655
+ >>> c = Counter(" ABCABC" )
656
656
>>> sorted(c.elements())
657
657
['A', 'A', 'B', 'B', 'C', 'C']
658
658
@@ -689,11 +689,11 @@ def update(self, iterable=None, /, **kwds):
689
689
690
690
Source can be an iterable, a dictionary, or another Counter instance.
691
691
692
- >>> c = Counter(' which' )
693
- >>> c.update(' witch') # add elements from another iterable
694
- >>> d = Counter(' watch' )
695
- >>> c.update(d) # add elements from another counter
696
- >>> c['h'] # four 'h' in which, witch, and watch
692
+ >>> c = Counter(" which" )
693
+ >>> c.update(" witch") # add elements from another iterable
694
+ >>> d = Counter(" watch" )
695
+ >>> c.update(d) # add elements from another counter
696
+ >>> c["h"] # four 'h' in which, witch, and watch
697
697
4
698
698
699
699
"""
@@ -725,12 +725,12 @@ def subtract(self, iterable=None, /, **kwds):
725
725
726
726
Source can be an iterable, a dictionary, or another Counter instance.
727
727
728
- >>> c = Counter(' which' )
729
- >>> c.subtract(' witch') # subtract elements from another iterable
730
- >>> c.subtract(Counter(' watch')) # subtract elements from another counter
731
- >>> c['h'] # 2 in which, minus 1 in witch, minus 1 in watch
728
+ >>> c = Counter(" which" )
729
+ >>> c.subtract(" witch") # subtract elements from another iterable
730
+ >>> c.subtract(Counter(" watch")) # subtract elements from another counter
731
+ >>> c["h"] # 2 in which, minus 1 in witch, minus 1 in watch
732
732
0
733
- >>> c['w'] # 1 in which, minus 1 in witch, minus 1 in watch
733
+ >>> c["w"] # 1 in which, minus 1 in witch, minus 1 in watch
734
734
-1
735
735
736
736
"""
@@ -841,7 +841,7 @@ def __gt__(self, other):
841
841
def __add__ (self , other ):
842
842
"""Add counts from two counters.
843
843
844
- >>> Counter(' abbb' ) + Counter(' bcc' )
844
+ >>> Counter(" abbb" ) + Counter(" bcc" )
845
845
Counter({'b': 4, 'c': 2, 'a': 1})
846
846
847
847
"""
@@ -860,7 +860,7 @@ def __add__(self, other):
860
860
def __sub__ (self , other ):
861
861
"""Subtract count, but keep only results with positive counts.
862
862
863
- >>> Counter(' abbbc' ) - Counter(' bccd' )
863
+ >>> Counter(" abbbc" ) - Counter(" bccd" )
864
864
Counter({'b': 2, 'a': 1})
865
865
866
866
"""
@@ -879,7 +879,7 @@ def __sub__(self, other):
879
879
def __or__ (self , other ):
880
880
"""Union is the maximum of value in either of the input counters.
881
881
882
- >>> Counter(' abbb' ) | Counter(' bcc' )
882
+ >>> Counter(" abbb" ) | Counter(" bcc" )
883
883
Counter({'b': 3, 'c': 2, 'a': 1})
884
884
885
885
"""
@@ -899,7 +899,7 @@ def __or__(self, other):
899
899
def __and__ (self , other ):
900
900
"""Intersection is the minimum of corresponding counts.
901
901
902
- >>> Counter(' abbb' ) & Counter(' bcc' )
902
+ >>> Counter(" abbb" ) & Counter(" bcc" )
903
903
Counter({'b': 1})
904
904
905
905
"""
@@ -942,8 +942,8 @@ def _keep_positive(self):
942
942
def __iadd__ (self , other ):
943
943
"""Inplace add from another counter, keeping only positive counts.
944
944
945
- >>> c = Counter(' abbb' )
946
- >>> c += Counter(' bcc' )
945
+ >>> c = Counter(" abbb" )
946
+ >>> c += Counter(" bcc" )
947
947
>>> c
948
948
Counter({'b': 4, 'c': 2, 'a': 1})
949
949
@@ -955,8 +955,8 @@ def __iadd__(self, other):
955
955
def __isub__ (self , other ):
956
956
"""Inplace subtract counter, but keep only results with positive counts.
957
957
958
- >>> c = Counter(' abbbc' )
959
- >>> c -= Counter(' bccd' )
958
+ >>> c = Counter(" abbbc" )
959
+ >>> c -= Counter(" bccd" )
960
960
>>> c
961
961
Counter({'b': 2, 'a': 1})
962
962
@@ -968,8 +968,8 @@ def __isub__(self, other):
968
968
def __ior__ (self , other ):
969
969
"""Inplace union is the maximum of value from either counter.
970
970
971
- >>> c = Counter(' abbb' )
972
- >>> c |= Counter(' bcc' )
971
+ >>> c = Counter(" abbb" )
972
+ >>> c |= Counter(" bcc" )
973
973
>>> c
974
974
Counter({'b': 3, 'c': 2, 'a': 1})
975
975
@@ -983,8 +983,8 @@ def __ior__(self, other):
983
983
def __iand__ (self , other ):
984
984
"""Inplace intersection is the minimum of corresponding counts.
985
985
986
- >>> c = Counter(' abbb' )
987
- >>> c &= Counter(' bcc' )
986
+ >>> c = Counter(" abbb" )
987
+ >>> c &= Counter(" bcc" )
988
988
>>> c
989
989
Counter({'b': 1})
990
990
0 commit comments