2019独角兽企业重金招聘Python工程师标准>>>
Word Frequency(https://leetcode.com/problems/word-frequency/description/)
Example:
Assume that words.txt
has the following content:
the day is sunny the the the sunny is is
Your script should output the following, sorted by descending frequency:
the 4 is 3 sunny 2 day 1
然后来看看强大的 awk
awk -vRS='( |\n)+' '{a[$0]++}END{for(i in a)m[a[i]]=i;i=asort(a);for(;i;)print m[a[i]],a[i--]}' words.txt