list/tuple/dict question

Fredrik Lundh fredrik at pythonware.com
Sun Aug 17 23:42:07 CEST 2008


bruce wrote:

> so, this still doesn't get me an array called 'cat', or 'dog'

sure does, in the stuff dictionary:

 >>> stuff = {}
 >>> foo = []
 >>> foo.append('cat')
 >>> foo.append('dog')
 >>> stuff[foo[1]] = []
 >>> stuff
{'dog': []}

(note that Python indexing starts with zero, so foo[1] refers to the dog 
entry).

> or do i somehow use stuff to add/extract the vals...???

    >>> stuff["dog"]
    []
    >>> stuff["dog"].append(1)
    >>> stuff["dog"]
    [1]

etc.

</F>




More information about the Python-list mailing list