Skip to content

Instantly share code, notes, and snippets.

@dahu
Last active August 29, 2015 14:02
Show Gist options
  • Save dahu/0e454b3951ac843b58ae to your computer and use it in GitHub Desktop.
Save dahu/0e454b3951ac843b58ae to your computer and use it in GitHub Desktop.
osse's freqs
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