I am trying to join an arbitrarily long list of dictionaries into one dictionary where matching keys will take the union of distinct values and new keys are simply inserted. Is there a way to do that using uj?
dd1:(`a`b`c)!(1 2; 3 4; 5 6);
dd2:(`b`c`d)!(7 8; 9 10; 0 1);
dd3:(`a`f`e)!(3 4; 1 1; 2 2);
(uj)/:(dd1;dd2;dd3) just returns the last dict.
What I want is:
(`a`b`c`d`e`f)!(1 2 3 4; 3 4 7 8; 5 6 9 10; 0 1; 2 2; 1 1)
>Solution :
One method not using uj
q)(,'/)(dd1;dd2;dd3)
a| 1 2 3 4
b| 3 4 7 8
c| 5 6 9 10
d| 0 1
f| 1 1
e| 2 2
If the order of the keys is important
q)`a`b`c`d`e xcols(,'/)(dd1;dd2;dd3)
a| 1 2 3 4
b| 3 4 7 8
c| 5 6 9 10
d| 0 1
e| 2 2
f| 1 1
To ensure only distinct values are taken
q)distinct each(,'/)(dd1;dd2;dd3)
a| 1 2 3 4
b| 3 4 7 8
c| 5 6 9 10
d| 0 1
f| ,1
e| ,2