[Tutor] Dictionary within a dictionary

Kent Johnson kent37 at tds.net
Sat Jun 14 13:34:58 CEST 2008


On Fri, Jun 13, 2008 at 10:23 AM, qsqgeekyogdty at tiscali.co.uk
<qsqgeekyogdty at tiscali.co.uk> wrote:
> Hi,
> Following Alan's post, what I was trying to do is to understand how I
> can return the sub-item within the same space, if it makes sense ;)

Um, no, not to me. Is your question about creating a structure or accessing it?

> For example, in my 3 one-to-many lists, I want to generate this list:
>
>          [{'id': <group id>,
>            'category': [{'id': <category id>,
>                        'sub-category': [ {'id': <sub-category id>,
>                                     'title': <sub-category title>,
>                                     'is_selected': <True | False>
>                                    }
>                                  ...]
>                        'title': <category title>,
>                        'is_selected': <True | False>
>                        }
>                     ...]
>            'title': <group title>,
>            'is_selected': <True | False>,
>            }
>           ...]

And this data is coming from a database? If it is fixed you can just
create it as you did above; if you filled in actual values that would
be valid Python code.

Do you have any code you have tried?  It helps to get specific. I
still don't really understand what you are having trouble with. Is it
- deciding on the best structure to represent the data
- reading from a database and creating a nested structure
- accessing a nested structure
?

Kent


More information about the Tutor mailing list