Recursively adding to list in dictionary

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

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

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

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 <attila.vrab…> wrote:> executable input and simple to follow examples are preferred…> you only need one dictionary>> q)d:abcde!bcde> q)scan[d]each d> a| bcde&gt; b| cde&gt; c| de> d| e> e| ,&gt; ? Attila&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; On Tue, Oct 11, 2011 at 8:13 AM, Daniel <cas...> wrote:&gt; &gt; I have two dictionaries.&gt;&gt; &gt; The first has a key of a symbol and value a list of symbols being&gt; &gt; itself plus its related parent.&gt;&gt; &gt; i.e&gt;&gt; &gt; opbpj| opbpj fnadb&gt; &gt; fnadb| fnadb hadmc&gt; &gt; hadmc| hadmc jjjoa&gt; &gt; jjjoa| jjjoa aglag&gt; &gt; aglag| aglag >> > The second is a dictionary linking symbols with their related parent.>> > opbpj| fnadb> > fnadb| hadmc> > hadmc| jjjoa> > jjjoa| aglag> > aglag| &gt;&gt; &gt; I want to take the last item in the each of the items in the first&gt; &gt; dictionary and append its parent if it has one.&gt; &gt; After appending the parent I also want to check if that also has a&gt; &gt; parent and append that.&gt;&gt; &gt; Result of&gt;&gt; &gt; opbpj| opbpj fnadb hadmc jjjoa aglag > > fnadb| fnadb hadmc jjjoa aglag &gt; &gt; hadmc| hadmc jjjoa aglag > > jjjoa| jjjoa aglag &gt; &gt; aglag| aglag >> > In this example they are in order but thats not an assumption I can> > make.>> > Any advice would be appreciated.>> > Thanks,> > Daniel>> > –> >

Submitted via Google Groups</cas…></attila.vrab…>

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

d:opbpjfnadbhadmcjjjoaaglag!(opbpjfnadb;fnadbhadmc;hadmcjjjoa;jjjoaaglag;aglag)d2:opbpjfnadbhadmcjjjoaaglag!(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 <cas...> wrote:&gt; I have two dictionaries.&gt;&gt; The first has a key of a symbol and value a list of symbols being&gt; itself plus its related parent.&gt;&gt; i.e&gt;&gt; opbpj| opbpj fnadb&gt; fnadb| fnadb hadmc&gt; hadmc| hadmc jjjoa&gt; jjjoa| jjjoa aglag&gt; aglag| aglag >> The second is a dictionary linking symbols with their related parent.>> opbpj| fnadb> fnadb| hadmc> hadmc| jjjoa> jjjoa| aglag> aglag| &gt;&gt; I want to take the last item in the each of the items in the first&gt; dictionary and append its parent if it has one.&gt; After appending the parent I also want to check if that also has a&gt; parent and append that.&gt;&gt; Result of&gt;&gt; opbpj| opbpj fnadb hadmc jjjoa aglag > fnadb| fnadb hadmc jjjoa aglag &gt; hadmc| hadmc jjjoa aglag > jjjoa| jjjoa aglag &gt; aglag| aglag >> In this example they are in order but thats not an assumption I can> make.>> Any advice would be appreciated.>> Thanks,> Daniel</cas…>