Skip to content

Instantly share code, notes, and snippets.

@jfsantos
Last active January 3, 2016 04:59
Show Gist options
  • Save jfsantos/8412953 to your computer and use it in GitHub Desktop.
Save jfsantos/8412953 to your computer and use it in GitHub Desktop.
function groupby{T}(fn::Function, seq::Array{T})
dict = Dict{Any, Array{T}}();
for item in seq
key = fn(item);
if !haskey(dict, key)
dict[key] = [];
end
push!(dict[key], item);
end
return dict;
end
function processdata(file::String)
filename = ARGS[1];
file = open(filename);
lines = readlines(file);
#lines = convert(Array{String, 1}, map(strip, lines));
lines = map(strip, lines)
word_pairs = map(s->split(s, ','), lines);
result = groupby(a->a[1], word_pairs);
end
processdata("test.txt")
@time begin
result = processdata(ARGS[1]);
end
it, was
was, the
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment