-
Default dictionary value
How do I force a default value of key in dictionary when key is not preset. For example, say I have list of dictionaries
t `key`delayed`assetMainType`assetSubType`cusip`1`2`3`4`6`7`8!("LPL";0b;"EQUITY";"ADR";"50186V102";9.03;9.4;9.25;1f;," ";,"P";1101592f) `key`delayed`assetMainType`cusip`1`2`3`4`5`6`7`8!("NFLX";0b;"EQUITY";"64110L106";396.05;396.5;396.05;2f;4f;,"Q";,"P";5.890427e+07) `key`delayed`assetMainType`cusip`1`2`3`4`5`6`7`8!("LAZR";0b;"EQUITY";"550424105";13.16;13.25;13.19;4f;1f;,"P";,"P";1.450048e+07)
First in the list doesn’t have key “1 so vector operation like xkey would be a problem because key length is not same. So other way is to write something below in cond “?'” operation to get default value 99
{ca:`key`1`2`3`4`5`6`7`8 in key x;val:t[`key`1`2`3`4`5`6`7`8];?[ca;val;enlist enlist 99]} each t
But this gives error `length. I can assure that length of ca, val is same and is 9.
May be my solution is convoluted that is why I am asking the question in simplified example
q)d:`a`b`c!("";2;3) q)d[`d] ""
If `d is not available in dict d, I want to return 99 instead of “”
Log in to reply.