Created
March 3, 2012 20:12
-
-
Save anonymous/1967974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.9.2p290 :006 > string | |
=> "doo bee doo bee" | |
1.9.2p290 :007 > string="doo bee doo bee" | |
=> "doo bee doo bee" | |
1.9.2p290 :008 > string=string.downcase.split | |
=> ["doo", "bee", "doo", "bee"] | |
1.9.2p290 :009 > string | |
=> ["doo", "bee", "doo", "bee"] | |
1.9.2p290 :010 > def count_w(list) | |
1.9.2p290 :011?> c=Hash.new(0) | |
1.9.2p290 :012?> for a_word in list | |
1.9.2p290 :013?> c[a_word]+=1 | |
1.9.2p290 :014?> end | |
1.9.2p290 :015?> c | |
1.9.2p290 :016?> end | |
=> nil | |
1.9.2p290 :017 > count_w(string) | |
=> {"doo"=>2, "bee"=>2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment