[Tutor] A couple of somewhat esoteric questions
Dave Angel
davea at davea.name
Thu Oct 23 02:31:38 CEST 2014
"Clayton Kirkwood" <crk at godblessthe.us> Wrote in message:
>
>
> !-----Original Message-----
> !From: Tutor [mailto:tutor-bounces+crk=godblessthe.us at python.org] On
> !Behalf Of Steven D'Aprano
...
>
> For clarification, a key only has one value which can be changed.
No, because the key has to be immutable, like a string or an int.
> Multiple
> keys can have the same value (hopefully not to the same memory location,
> because one would usually not want the change of one key's value to alter
> another key's value. As to the hash table, yes, I agree that this would be
> one to many, hence the chains.
Memory locations are an implementation detail. We're talking in
this paragraph about keys and values. A value is an object, the
dict provides a one-way mapping from immutable key to an
arbitrary value object. If the value objects happen to be
immutable, it makes no difference if a program uses the same
value for multiple keys. If the values are not immutable, python
makes no assurance whether two values are equal, or identical. If
the latter is undesirable for a particular use, it's up to the
application logic to prevent it. It's probably more often useful
than problematic. Python makes no such assurances.
> !Can you give a concrete example of what you're trying to do?
>
> The changing of the order is necessary when you want numeric indexing, say
> for columns or rows.
>
No idea how this relates to dicts, which have no order, nor rows
nor columns. Make it concrete.
--
DaveA
More information about the Tutor
mailing list