Category tree of some sort ...

Eddie Corns eddie at holyrood.ed.ac.uk
Mon Dec 9 13:15:39 EST 2002


"Thomas Weholt" <2002 at weholt.org> writes:

>I got a bunch of content categories in form of a list of lists :

>categories = [
>        ['computers','programming','python'],
>        ['computers','programming','c'],
>        ['computers','technical','os']
>]

>I need to put this into a tree-structure, a dictionary like this :

>category_tree = {
>    'computers': ([], {
>        'programming': ([], {
>            'python': ( [], {}),
>            'c': ( [], {}),
>        },
>    'technical': ([], {
>        'os': ([], {}),
>        }
>    }

>Each level holds a list of ids, pointing to resources on a local disk, the
>dict-part of each tuple is the base for a another, deeper level in the
>tree-structure.

>If anybody has any other idea on how to effectivly storing information about
>files where the folders are names of categories and each file is assigned a
>uniq id for look-up, please let me know.

You might be interested in reading chapter 7 of 'Practical issues in
Database Management' by Fabian Pascal where he discusses how to map tree
structures into relational tables thus giving you much greater flexibility
with looking up data.

Eddie



More information about the Python-list mailing list