Dictionary data types question

Erik Max Francis max at alcyone.com
Sun Mar 2 05:37:03 CET 2003

Alonde wrote:

> dict={"one":1}
> How when I entered 1 and it return "one"?

Python dictionaries are one-way mappings; there's no atomic means to
say, "Which key does this value correspond to?"  You could manually
search through the entries by calling D.items() or by iterating through
the sequence looking for the first value you wish.

Many keys can point to the same value (either by equality or by
identity); for instance, what would you expect to happen if you passed
it this dictionary?

	d = {'one': 1, 'two': 1, 'three': 1}

 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ The perfection of innocence, indeed, is madness.
\__/ Arthur Miller
    7 Sisters Productions / http://www.7sisters.com/
 Web design for the future.

More information about the Python-list mailing list