Last active
August 29, 2015 14:02
osse's freqs
This file contains hidden or 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
function! LetThereBeKeys(dict, list, default) | |
let dict = a:dict | |
call map(copy(a:list), 'extend(dict, {v:val : get(dict, v:val, a:default)})') | |
return dict | |
endfunction | |
function! Freqs2(list) | |
let freqs = {} | |
let words = split(join(getline(1, '$'))) | |
call map(copy(a:list) | |
\ , 'extend(freqs, {v:val : ' | |
\ . 'len(filter(copy(words), ''v:val =~ "\\<'' . v:val . ''\\>"''))})') | |
return freqs | |
endfunction | |
function! Freqs(list) | |
let freqs = {} | |
for line in getline(1, '$') | |
for word in a:list | |
if line =~ '\<' . word . '\>' | |
let freqs[word] = get(freqs, word, 0) + 1 | |
endif | |
endfor | |
endfor | |
return freqs | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment