```d
import std;

auto data=“I went for a walk, and fell down a hole.”;

void main(string[] args) {
    int[string] dic;
    struct WordCnt {
        string word;
        ulong count;
        string toString() const {
return text("Word: ", word, " - number of instances: ", count);
        }
    }
    WordCnt[] wc;
    data
.map!(c => lowercase.canFind(std.uni.toLower(c)) ? c : ' ')
        .to!string
        .splitter
        .each!(d => dic[d]+=1);
    foreach(key, value; dic)
        wc~=WordCnt(key, value);
    wc.sort!"a.count>b.count".each!writeln;
}
```

How can I improve this code? Like avoiding using foreach.

Reply via email to