-
Notifications
You must be signed in to change notification settings - Fork 89
Using System.Collections.Generic.Dictionary
NN--- edited this page Apr 11, 2012
·
5 revisions
- Category: Arrays, Hash Tables and Dictionaries
- Description: Create a histogram of the occurrences of particular unicode characters using a dictionary.
- Code:
using Nemerle.Collections;
using System.Console;
def tab = Hashtable(30);
def data = "The quick brown fox jumps over the lazy dog";
foreach (c in data)
tab[c] = tab.GetValueOrDefault(c) + 1;
foreach ((k, v) in tab.KeyValuePairs)
WriteLine($"Number of '$k' characters = $v");
- Execution Result:
Number of 'T' characters = 1
Number of 'h' characters = 2
Number of 'e' characters = 3
Number of ' ' characters = 8
Number of 'q' characters = 1
Number of 'u' characters = 2
Number of 'i' characters = 1
Number of 'c' characters = 1
Number of 'k' characters = 1
Number of 'b' characters = 1
Number of 'r' characters = 2
Number of 'o' characters = 4
Number of 'w' characters = 1
Number of 'n' characters = 1
Number of 'f' characters = 1
Number of 'x' characters = 1
Number of 'j' characters = 1
Number of 'm' characters = 1
Number of 'p' characters = 1
Number of 's' characters = 1
Number of 'v' characters = 1
Number of 't' characters = 1
Number of 'l' characters = 1
Number of 'a' characters = 1
Number of 'z' characters = 1
Number of 'y' characters = 1
Number of 'd' characters = 1
Number of 'g' characters = 1
[Copyright ©](Terms of use, legal notice)