Viriya
Viriya

Reputation: 177

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.

Upvotes: 3

Views: 3002

Answers (2)

Akash
Akash

Reputation: 131

q)f:{[x] value ssr["(",.Q.s1[x],")";"!";";"]}
q)f[x]
ab
(ce;20 30;hg;(4;ij;26 7))

Upvotes: -1

Bartosz Kaliszuk
Bartosz Kaliszuk

Reputation: 131

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)))))

Upvotes: 2

Related Questions