Search code examples
kdb

Dictionary to list kdb


I'm trying to setup a function that takes a nested dictionary and replaces each dictionary with a pair of lists:

For example:

$ x:`a`b!(`c`e!20 30;`h`g!(4;`i`j!26 7))    

$ dict2List d
(`a`b;((`c`e;20 30);(`h`g;(4;(`i`j;26 7)))))

Any ideas appreciated.


Solution

  • It's just unwrapping dictionaries with (key;value):

    q)f:{:$[99h=type x;(key x;.z.s each value x);x]}
    q)d:`a`b!(`c`e!20 30;`h`g!(4;`i`j!26 7))
    q)f d
    (`a`b;((`c`e;20 30j);(`h`g;(4j;(`i`j;26 7j)))))