How to Convert String to Key Value Map of Items and Count Number

From ElixirBlocks
Revision as of 04:58, 2 September 2023 by Admin (talk | contribs) (Created page with "<source> words = "The world hello world to the world" list = String.split(words," ") Enum.map(list, fn(item)-> item end)|> Enum.frequencies()|> IO.inspect #%{"The" => 1, "hello" => 1, "the" => 1, "to" => 1, "world" => 3} </source>")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
words = "The world hello world to the world"

list = String.split(words," ")
Enum.map(list, fn(item)->  item end)|>
Enum.frequencies()|>
IO.inspect              #%{"The" => 1, "hello" => 1, "the" => 1, "to" => 1, "world" => 3}