File tree 2 files changed +12
-9
lines changed 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -509,11 +509,14 @@ def remove_by_threshold(self, threshold: int = 5) -> None:
509
509
510
510
def _update_dictionary (self ) -> None :
511
511
"""Update the word frequency object"""
512
- self ._longest_word_length = 0
512
+ if not self ._dictionary :
513
+ self ._longest_word_length = 0
514
+ self ._total_words = 0
515
+ self ._unique_words = 0
516
+ self ._letters = set ()
517
+ return
518
+ keys = self ._dictionary .keys ()
519
+ self ._longest_word_length = max (map (len , keys ))
513
520
self ._total_words = sum (self ._dictionary .values ())
514
- self ._unique_words = len (self ._dictionary .keys ())
515
- self ._letters = set ()
516
- for key in self ._dictionary :
517
- if len (key ) > self ._longest_word_length :
518
- self ._longest_word_length = len (key )
519
- self ._letters .update (key )
521
+ self ._unique_words = len (keys )
522
+ self ._letters = set ().union (* keys )
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def decorator_wrapper(func):
25
25
def test_inner (* args , ** kwargs ):
26
26
if [int (x ) for x in version .split ("." )] <= [int (x ) for x in __version__ .split ("." )]:
27
27
msg = (
28
- f"The function { func .__name__ } must be fully removed as it is depricated "
28
+ f"The function { func .__name__ } must be fully removed as it is deprecated "
29
29
f" and must be removed by version { version } "
30
30
)
31
31
raise AssertionError (msg )
@@ -76,7 +76,7 @@ def ensure_unicode(value: KeyT, encoding: str = "utf-8") -> str:
76
76
if isinstance (value , bytes ):
77
77
return value .decode (encoding )
78
78
elif isinstance (value , list ):
79
- raise TypeError (f"The provided value { value } is a not of type str or bytes" )
79
+ raise TypeError (f"The provided value { value } is not of type str or bytes" )
80
80
return value
81
81
82
82
You can’t perform that action at this time.
0 commit comments