Transform list into dictionary

Discussions, advice, bug reports and much more about the "bach" environment.
Post Reply
sydy
Posts: 156
Joined: Tue Mar 21, 2017 1:34 pm

Transform list into dictionary

Post by sydy » Thu Jun 06, 2019 10:56 am

Hy, (me again)
I have a (sorted) list of N items.
I want to transform these items into a dictionary with subdictionaries.
Each number, besides the last, is a dictionary level (category).

E.G. With of a list containing list items made by 3 characters
Listitem1: 111
Listitem2: 112
Listitem3: 113
Listitem4: 121
Listitem5: 221
Listitem6: 222
etc.

Listitem1-4 are organized in the first category of the first level and so on...
Level1 (1)
----Level2 (1)
------Values level2 (1): [1,2,3]
----Level2 (2)
------Values of level2 (2): [1]

Listitem5-6 go into the second category of the first level and so on...
Level1 (2)
----Level2 (2)
------Values of level2 (2) : [1, 2]

Is there a simple way to do that in bach? – I tried to find a way but wasn't very successful...

Thanks for your help.
m

danieleghisi
Site Admin
Posts: 1349
Joined: Fri Dec 03, 2010 1:25 pm

Re: Transform list into dictionary

Post by danieleghisi » Thu Jun 06, 2019 8:16 pm

Hi, not sure I've understood exactly how your list is made up, but I'd suggest to take a look at [bach.classify] and [bach.llll2dict], they may (or may not...) be of some help in your case!

Post Reply