Updating python dictionary

John Machin sjmachin at lexicon.net
Tue Sep 9 01:33:42 CEST 2008


On Sep 9, 6:12 am, "andyh... at gmail.com" <andyh... at gmail.com> wrote:
[big snip]
> In the interests of academia (although this isn't homework :)) I'll
> answer some of those questions:

Understanding your own requirements is , I would have thought, not
much to do with "academia" but a very practical idea.

>
> - Yes, the mapping dict doesn't necessarily have the same number of
> entries as the my_dict. It may have less than it or more than it.

What behaviour do you expect when there is a key in my_dict that is
not in the mapping?

> - There will never be dupes of key or value in the mapping. Though
> there maybe in my_dict.

If there are ever any dupes of a key in a Python dict object, it will
be the end of civilisation as we know it.

How are you are guaranteeing that there are no value dupes in your
mapping? What are the consequences if a dupe sneaks in?

>
> And, for extra credit, it may be useful to be able to 'translate' the
> my_dict back again using the same mapping_dict. ie, using the values
> in mapping dict as the new keys in my_dict, and the keys as the new
> values.

"... as the new values" of what? my_dict?? Don't you mean something
like "using the values in mapping dict as the keys in reverse_mapping,
and the keys as the values in reverse_mapping"?

Cheers,
John



More information about the Python-list mailing list