int[string] wordCount(string[] wordList) {
int[string] words;
foreach (word; wordList) {
words[word]++;
}
return words;
}
void main() {
int[string] count = wordCount(["hello", "world", "I", "say", "hello"]);
foreach (key; count.keys) {
writefln("%s: %s", key, count[key]);
}
// 你好:2
// 世界:1
// 我:1
// 说:1
// 注意:foreach中的顺序未指定
}