dictionaries with nested lists

Alex Martelli aleax at aleax.it
Sat Nov 1 17:38:46 EST 2003


ruari mactaggart wrote:

> what if i mean
>
bands={'beatles':['john','paul','george','ringo'],['guitar','bass','guitar',
> 'drums']}

Invalid syntax.

> then i need to put bands['beatles'][1][3]='percussion'

If you mean that bands is a dictionaries of tuples of lists, yes, but you
need parentheses around the tuples (and I would suggest some formatting
for greater readability), e.g.:

bands = {'beatles': ( ['john', 'paul', 'george', 'ringo'],
                      ['guitar', 'bass', 'guitar', 'drums'] )
        }


Alex





More information about the Python-list mailing list