Numune girişi:Kelime sıklığı ruby ile verimli şekilde nasıl alınır?
"I was 09809 home -- Yes! yes! You was"
ve çıkışı:
{ 'yes' => 2, 'was' => 2, 'i' => 1, 'home' => 1, 'you' => 1 }
Kodum çalışmıyor:
def get_words_f(myStr)
myStr=myStr.downcase.scan(/\w/).to_s;
h = Hash.new(0)
myStr.split.each do |w|
h[w] += 1
end
return h.to_a;
end
print get_words_f('I was 09809 home -- Yes! yes! You was');
çok ilgili: http://stackoverflow.com/questions/9480852/array-to-hash-words-count – tokland