Home › Forums › kdb+ › Swap key-value in dictionary › Re: Swap key-value in dictionary
-
This achieves what you’re looking for.
q)d:1 2 3!(4 5 3;6 7 3;4 1) q)r:1 3 4 5 6 7!(enlist 3;1 2;1 3;enlist 1;enlist 2;enlist 2) q){a!key[x]where each flip value(a:asc distinct raze x)in/:x} d 1| ,3 3| 1 2 4| 1 3 5| ,1 6| ,2 7| ,2 q)r~{a!key[x]where each flip value(a:asc distinct raze x)in/:x}d 1b