Why no list as dict key?
Peter J. Holzer
hjp-python at hjp.at
Mon Apr 25 09:54:31 EDT 2022
On 2022-04-25 15:13:19 +0200, Lars Liedtke wrote:
> May I stupidly ask, why one would want to use an iterable (even immutable)
> as dict key?
A string is also an immutable iterable, so this is probably even the
most common case.
As for more complex data structures:
* Tuples or immutable dicts are a good fit if want to group records by
subset of their attributes (think "group by" in SQL)
* Objects in general are often though of as units, even if they have
composite values and you might want to look up something by that
value.
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20220425/ab574712/attachment.sig>
More information about the Python-list
mailing list