When apply value function to a dictionary, is the order maintained?

Hi experts,

What I want to do is changing the key of my dictionary. e.g. I have a dictionary
> d:(1 2 3)!(4 5 6);
I want to increase each key value by 1.

The solution that I come up with is

  1. Extract all values from the dict, as well as the keys, as two lists.
  2. Then apply operations on the key list.
  3. Finally, join the new key list with the value list to form a new dictionary.

> d:((key d) + 1)!(value d);

So the question is, can value function maintain the order of values?
Besides, is there other elegant method to implement this?

Thank you for your time!
Shuang

Order is maintained and your approach seems good to me.

You can avoid some of the parenthesis in q:<o:p></o:p>

<o:p> </o:p>

(1+key d)!value d<o:p></o:p>

<o:p> </o:p>

Or if you like you can also use adverbs<o:p></o:p>

<o:p> </o:p>

(!). 1 0+(key;value)@:d<o:p></o:p>

<o:p> </o:p>

Kim<o:p></o:p>

<o:p> </o:p>

Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von wp
Gesendet: Dienstag, 22. April 2014 09:21
An: personal-kdbplus@googlegroups.com
Betreff: Re: [personal kdb+] When apply value function to a dictionary, is the order maintained?<o:p></o:p>

<o:p> </o:p>

Order is maintained and your approach seems good to me.<o:p></o:p>

On Apr 22, 2014 8:01 AM, “Shuang Qiu” <qshhnkf@gmail.com> wrote:<o:p></o:p>

Hi experts,

What I want to do is changing the key of my dictionary. e.g. I have a dictionary
> d:(1 2 3)!(4 5 6);
I want to increase each key value by 1.

The solution that I come up with is<o:p></o:p>

  1. Extract all values from the dict, as well as the keys, as two lists.<o:p></o:p>
  2. Then apply operations on the key list.<o:p></o:p>
  3. Finally, join the new key list with the value list to form a new dictionary.<o:p></o:p>

> d:((key d) + 1)!(value d);

So the question is, can value function maintain the order of values?
Besides, is there other elegant method to implement this?

Thank you for your time!
Shuang<o:p></o:p>


Submitted via Google Groups

Just a small extension to the nice use of adverbs (suggested by kuentang) in the case when your dictionary values are symbols,  d:(1 2 3)!(AB`C)

(!). flip (1+key d) ,’ value d

still your own solution is most transpicuous