Quick actions

cmd+k|ctrl+k

Navigation

Languages

AP. Hashable as keys

Snippet info

Language

Python

Visibility

public

Author

weralwolf

Created

2015-08-23T09:55:14Z

Updated

2015-08-23T09:56:22Z

# -*- coding: utf-8 -*-

from __future__ import print_function

# Here's a small example of some possible (not all of them) values that
# can be used as dictionary keys. All of them are immutable.
key_fzs = frozenset({1, 2, 3})
key_str = "Amelie"
key_int = 2
key_dbl = 3.1415926
key_lng = 2**100

container = {
    key_fzs: "frozen set as key",
    key_str: "string as set",
    key_int: "integer value as key",
    key_dbl: "floating point number with double precision as key",
    key_lng: "long number as key"
}

print(container)
print(container[frozenset({1, 2, 3})])
INFO