Python Challenge -- Level 2 -- Native Solution
Code
import tango.io.Stdout; void main () { char[] text = ""; size_t[char[]] quantity; foreach (char letter; text) quantity["" ~ letter] += 1; foreach (char letter; text) if (quantity[""~letter] == 1) Stdout.print(key); Stdout.flush(); }
Explanation
char[] text = "";
The source text from the challenge page should be put between the quotes.
size_t[char[]] quantity;
An associative array is the easiest way to store information on each individual character.
foreach (inout char letter; text)
The code is executed for every character.
quantity["" ~ letter]++;
Increment the counter for the number of occurences of the current character. The concatenation is a workaround for the lack of implicit conversion between char and char![].
foreach (char letter; text)
Go again through all the text. The code is executed once for each character.
if (quantity[letter] == 1)
We only want characters that only were in the source text once.
Stdout.print(key); Stdout.flush();
Print the character to the screen, flushing upon completion.