cancel
Showing results for 
Search instead for 
Did you mean: 

Recursively adding to list in dictionary

Daniel
New Contributor
I have two dictionaries.The first has a key of a symbol and value a list of symbols beingitself plus its related parent.i.eopbpj| opbpj fnadbfnadb| fnadb hadmchadmc| hadmc jjjoajjjoa| jjjoa aglagaglag| aglag `The second is a dictionary linking symbols with their related parent.opbpj| fnadbfnadb| hadmchadmc| jjjoajjjoa| aglagaglag| `I want to take the last item in the each of the items in the firstdictionary and append its parent if it has one.After appending the parent I also want to check if that also has aparent and append that.Result ofopbpj| opbpj fnadb hadmc jjjoa aglag `fnadb| fnadb hadmc jjjoa aglag `hadmc| hadmc jjjoa aglag `jjjoa| jjjoa aglag `aglag| aglag `In this example they are in order but thats not an assumption I canmake.Any advice would be appreciated.Thanks,Daniel
4 REPLIES 4

Attila
New Contributor


executable input and simple to follow examples are preferred...
you only need one dictionary

q)d:`a`b`c`d`e!`b`c`d`e`
q)scan[d]each d
a| `b`c`d`e`
b| `c`d`e`
c| `d`e`
d| `e`
e| ,`
=A0 Attila

Daniel
New Contributor
Thanks Attila.list:distinct 1000?`5dict:list!1_list,`@[scan[dict] each dict;key dict;{,[y;x]};key dict]This is what I am now using as I need the original at the key at thestart also.On Oct 11, 3:38�pm, Attila Vrabecz wrote:> executable input and simple to follow examples are preferred...> you only need one dictionary>> q)d:`a`b`c`d`e!`b`c`d`e`> q)scan[d]each d> a| `b`c`d`e`> b| `c`d`e`> c| `d`e`> d| `e`> e| ,`> � Attila>>>>>>>> On Tue, Oct 11, 2011 at 8:13 AM, Daniel wrote:> > I have two dictionaries.>> > The first has a key of a symbol and value a list of symbols being> > itself plus its related parent.>> > i.e>> > opbpj| opbpj fnadb> > fnadb| fnadb hadmc> > hadmc| hadmc jjjoa> > jjjoa| jjjoa aglag> > aglag| aglag `>> > The second is a dictionary linking symbols with their related parent.>> > opbpj| fnadb> > fnadb| hadmc> > hadmc| jjjoa> > jjjoa| aglag> > aglag| `>> > I want to take the last item in the each of the items in the first> > dictionary and append its parent if it has one.> > After appending the parent I also want to check if that also has a> > parent and append that.>> > Result of>> > opbpj| opbpj fnadb hadmc jjjoa aglag `> > fnadb| fnadb hadmc jjjoa aglag `> > hadmc| hadmc jjjoa aglag `> > jjjoa| jjjoa aglag `> > aglag| aglag `>> > In this example they are in order but thats not an assumption I can> > make.>> > Any advice would be appreciated.>> > Thanks,> > Daniel>> > --> > You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.> > To post to this group, send email to personal-kdbplus@googlegroups.com.> > To unsubscribe from this group, send email to personal-kdbplus+unsubscribe@googlegroups.com.> > For more options, visit this group athttp://groups.google.com/group/personal-kdbplus?hl=en.

Attila
New Contributor


key[d],'scan[d]each d:{x!next x} -1000?`5
=A0 Attila

rathore_ajay
New Contributor
d:`opbpj`fnadb`hadmc`jjjoa`aglag!(`opbpj`fnadb;`fnadb`hadmc;`hadmc`jjjoa;`jjjoa`aglag;`aglag`)d2:`opbpj`fnadb`hadmc`jjjoa`aglag!(`fnadb;`hadmc;`jjjoa;`aglag;`){x, raze {[y] l:();while[not null y;y:d2[y];l,:y];:l}each -1#x}each dOn Oct 11, 12:13�pm, Daniel wrote:> I have two dictionaries.>> The first has a key of a symbol and value a list of symbols being> itself plus its related parent.>> i.e>> opbpj| opbpj fnadb> fnadb| fnadb hadmc> hadmc| hadmc jjjoa> jjjoa| jjjoa aglag> aglag| aglag `>> The second is a dictionary linking symbols with their related parent.>> opbpj| fnadb> fnadb| hadmc> hadmc| jjjoa> jjjoa| aglag> aglag| `>> I want to take the last item in the each of the items in the first> dictionary and append its parent if it has one.> After appending the parent I also want to check if that also has a> parent and append that.>> Result of>> opbpj| opbpj fnadb hadmc jjjoa aglag `> fnadb| fnadb hadmc jjjoa aglag `> hadmc| hadmc jjjoa aglag `> jjjoa| jjjoa aglag `> aglag| aglag `>> In this example they are in order but thats not an assumption I can> make.>> Any advice would be appreciated.>> Thanks,> Daniel
-Ajay