...

/

Solution: Swap Keys with Values of an Associative Array

Solution: Swap Keys with Values of an Associative Array

This lesson provides a solution to the challenge given in the previous lesson.

We'll cover the following...

Solution #

Here is the code that will swap the keys with values of an associative array.

Press + to interact
import std.stdio;
void Swap() {
string[int] names = [ 1:"one", 7:"seven", 20:"twenty" ];
int[string] values;
foreach (key, value; names) {
values[value] = key;
}
writeln(values["twenty"]);
}
...