appending to dict

Holger Türk htx1 at gmx.de
Fri May 14 05:55:21 EDT 2004



bucket79 wrote:
> why a.keys().append(3) makes 'None' ?

Because .append modifies the list in place. It does
not return a new list.

> and is there anyway appending to dictionary?

key/value pairs in a dictionary are not ordered. There
is no "last pair". So you can't append to a dictionary.
But you can update it with another dictionary.
Use something like: adict.update (anotherdict)

keys () returns a list of keys in the dictionary.
The order of the elements in this list is arbitrary
(or somehow ordered afterwards). But there is no
real list of keys in the dictionary itself.

Greetings,

Holger




More information about the Python-list mailing list