Hi guys,
I have list that looks something like this:
(list
(list "Country" "America") (list "State" "California") (list "City" "Los Angeles") (list "Town" "AAA")
(list "Country" "America") (list "State" "Alaska") (list "City" "Anchorage") (list "Town" "CCC")
(list "Country" "America") (list "State" "California") (list "City" "Adelanto") (list "Town" "AAA")
(list "Country" "Australia") (list "State" "Vitoria") (list "City" "Melbourne") (list "Town" "XXX")
...
)
I have been thinking how to turn it to something like the following but has no clue.
(list
(list (list "Counrty" "America")
(list
(list (list "State" "California")
(list
(list (list "City" "Los Angeles")
(list "Town" (list "AAA" "BBB" ... ))
)
(list (list "City" "Adelanto")
(list "Town" (list "AAA" "HHH" ...))
)
...
)
(list (list "State" "Alaska")
....
)
)
)
(list (list "Counrty" "Australia")
...
)
...
)
In short, I wanna make it look a 'tree' type list. The above is just an example. I am looking for a function to make it work for all this kind of lists.
The reason why I wanna revise this list like this is because I can get, say the towns under "America"-"California"-"Los Angeles" or any other towns under other Country-State-City, or any cities under any Country-State etc by using 'assoc' with the 'tree' type list so I dont need to go through the original list everytime.
This final tree type list can look different as long as you think it works better to get the 'sub-list' easier.
Any thoughts?
Thank you.