-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassociatedArray.d
47 lines (37 loc) · 1.57 KB
/
associatedArray.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module test;
@safe:
import std;
void main()
{
auto OmicronAA =
([
"BA.3" : [ ["G142D", "G339D", "S373P", "S375F", "S371F", "D405N"] : [1, 1, 1, 1, 1, 1],
["D614G", "H655Y", "N679K", "P681H", "N764K", "D796Y"] : [1, 0, 1, 0, 1, 1]
],
"BA.2" : [ ["G142D", "G339D", "S373P", "S375F", "S371F", "D405N"] : [1, 1, 1, 1, 1, 1],
["D614G", "H655Y", "N679K", "P681H", "N764K", "D796Y"] : [1, 0, 1, 0, 1, 0]
],
"BA.1" : [ ["G142D", "G339D", "S373P", "S375F", "S371F", "D405N"] : [1, 0, 0, 1, 0, 0],
["D614G", "H655Y", "N679K", "P681H", "N764K", "D796Y"] : [1, 1, 0, 1, 0, 0]
]
]);
string[] orderedKeyPairSet;
foreach (ref owner, ref key_value; OmicronAA.byPair)
{
foreach(ref key, ref value; key_value.byPair)
orderedKeyPairSet ~= owner ~ ":" ~ key.to!string ~ ":" ~ value.to!string ~ ":" ~ value.sum.to!string;
}
orderedKeyPairSet.sort;
foreach(ref str; orderedKeyPairSet)
writeln(str);
writeln;
}
/+
outputs this:
BA.1:["D614G", "H655Y", "N679K", "P681H", "N764K", "D796Y"]:[1, 1, 0, 1, 0, 0]:3
BA.1:["G142D", "G339D", "S373P", "S375F", "S371F", "D405N"]:[1, 0, 0, 1, 0, 0]:2
BA.2:["D614G", "H655Y", "N679K", "P681H", "N764K", "D796Y"]:[1, 0, 1, 0, 1, 0]:3
BA.2:["G142D", "G339D", "S373P", "S375F", "S371F", "D405N"]:[1, 1, 1, 1, 1, 1]:6
BA.3:["D614G", "H655Y", "N679K", "P681H", "N764K", "D796Y"]:[1, 0, 1, 0, 1, 1]:4
BA.3:["G142D", "G339D", "S373P", "S375F", "S371F", "D405N"]:[1, 1, 1, 1, 1, 1]:6
+/