> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/w/word_frequency.md).

# Word frequency

```ruby
var count = Hash()
var file = File(ARGV[0] \\ '135-0.txt')

file.open_r.each { |line|
    line.lc.scan(/[\pL]+/).each { |word|
        count{word} := 0 ++
    }
}

var top = count.sort_by {|_,v| v }.last(10).flip

top.each { |pair|
    say "#{pair.key}\t-> #{pair.value}"
}
```

## Output:

```
the     -> 41088
of      -> 19949
and     -> 14942
a       -> 14596
to      -> 13951
in      -> 11214
he      -> 9648
was     -> 8621
that    -> 7924
it      -> 6661
```
