File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed
Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 22
33import re
44import sys
5- from typing import Dict
65
76
8- def word_count (text : str ) -> Dict [str , int ]:
9- counts = dict () # type: Dict [str, int]
10- words = re .split (r' \W+' , text )
7+ def word_count (text : str ) -> dict [str , int ]:
8+ counts : dict [str , int ] = dict ()
9+ words = re .split (r" \W+" , text )
1110 for word in words :
1211 word = word .lower ()
1312 if word not in counts :
1413 counts [word ] = 0
1514 counts [word ] += 1
1615 return counts
1716
18- if __name__ == '__main__' :
19- text = ' ' .join (sys .stdin .readlines ())
17+
18+ if __name__ == "__main__" :
19+ text = " " .join (sys .stdin .readlines ())
2020 counts = word_count (text )
2121 for word , count in counts .items ():
2222 if word :
23- print (f' { word } : { count } ' )
23+ print (f" { word } : { count } " )
Original file line number Diff line number Diff line change 22
33import re
44import sys
5- from typing import Dict
65
76
8- def word_count (text : str ) -> Dict [str , int ]:
9- counts = dict () # type: Dict [str, int]
10- words = re .split (r' \W+' , text )
7+ def word_count (text : str ) -> dict [str , int ]:
8+ counts : dict [str , int ] = dict ()
9+ words = re .split (r" \W+" , text )
1110 nr_words = 0
1211 for word in words :
1312 word = word .lower ()
1413 if word not in counts :
1514 counts [word ] = 0
1615 counts [word ] += 1
1716 nr_words += 1
18- nr_words -= counts .pop ('' )
17+ nr_words -= counts .pop ("" )
1918 for word , count in counts .items ():
2019 counts [word ] /= nr_words
2120 return counts
2221
23- if __name__ == '__main__' :
24- text = ' ' .join (sys .stdin .readlines ())
22+
23+ if __name__ == "__main__" :
24+ text = " " .join (sys .stdin .readlines ())
2525 counts = word_count (text )
2626 for word , count in counts .items ():
27- print (f' { word } : { count } ' )
27+ print (f" { word } : { count } " )
You can’t perform that action at this time.
0 commit comments