File tree Expand file tree Collapse file tree 2 files changed +1
-24
lines changed Expand file tree Collapse file tree 2 files changed +1
-24
lines changed Original file line number Diff line number Diff line change 1
1
from collections import Counter
2
2
3
3
4
- # to be backwards compatible with the old Python 2.X
5
- def decode_if_needed (string ):
6
- try :
7
- return string .decode ('utf-8' )
8
- except AttributeError :
9
- return string
10
-
11
-
12
4
def word_count (text ):
13
5
def replace_nonalpha (char ):
14
6
return char .lower () if char .isalnum () else ' '
15
- text = '' .join (replace_nonalpha (c ) for c in decode_if_needed ( text ) )
7
+ text = '' .join (replace_nonalpha (c ) for c in text )
16
8
return Counter (text .split ())
Original file line number Diff line number Diff line change 1
- # -*- coding: utf-8 -*-
2
1
import unittest
3
2
4
3
from word_count import word_count
5
4
6
5
7
- # to be backwards compatible with the old Python 2.X
8
- def decode_if_needed (string ):
9
- try :
10
- return string .decode ('utf-8' )
11
- except AttributeError :
12
- return string
13
-
14
-
15
6
class WordCountTests (unittest .TestCase ):
16
7
17
8
def test_count_one_word (self ):
@@ -78,12 +69,6 @@ def test_non_alphanumeric(self):
78
69
word_count ('hey,my_spacebar_is_broken.' )
79
70
)
80
71
81
- def test_unicode (self ):
82
- self .assertEqual (
83
- {decode_if_needed ('до' ): 1 , decode_if_needed ('свидания' ): 1 },
84
- word_count ('до🖖свидания!' )
85
- )
86
-
87
72
88
73
if __name__ == '__main__' :
89
74
unittest .main ()
You can’t perform that action at this time.
0 commit comments