Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'open-uri'
- words = open('http://history.eserver.org/soviet-diary.txt').read
- .scan(/(?:[a-zA-Z]+(?:['-][a-zA-Z]+)*|[A-Z]\.(?:[A-Z]\.)*)/).lazy
- .map(&:downcase).with_object({}) {|e, h| h[e] ||= 0; h[e] += 1}
- .to_a.sort_by {|(w, c)| [c, w]}.reverse
- top10 = words.take 10
- rest = words.drop 10
- top10.each {|(w, c)| puts "#{w}: #{c}"}
- puts "Rest: #{rest.size} words"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement