Frequency counting using associative arrays
// Frequency counting using associative arrays
var text := 'the quick brown fox jumps over the lazy dog';
var words := text.Split(' ');
var counts: array [String] of Integer;
for var w in words do
counts[w] := counts[w] + 1;
PrintLn('Word counts:');
for var w in counts.Keys do begin
PrintLn(' ' + w + ': ' + IntToStr(counts[w]));
end;
Word counts: over: 1 jumps: 1 dog: 1 quick: 1 lazy: 1 brown: 1 the: 2 fox: 1