4 ms·
If you want to compare memory efficiency. The sort+uniq -c would likely be more optimal in a high level language as you would there keep only the count+value i
by Too 6y ago
If you want to compare memory efficiency. The sort+uniq -c would likely be more optimal in a high level language as you would there keep only the count+value in a defaultdict or alike instead of sorting the entire dataset, which requires keeping it all in mem.
As for brevity, yeah, this particular example would require 5 lines instead of 1.
- citrin_ru 6y agoFor small datasets something like defaultdict may be more efficient, but if it would not fit in RAM you have a problem.