CKTIS / Python
Collections and keys
Choose a sequence for indexed positions, a set for unique hashable members and a dictionary for key-to-value lookup.
Version: Python 3.14; repository image, production runtime not attested
Syntax
dict.fromkeys(labels)Choose a sequence for indexed positions, a set for unique hashable members and a dictionary for key-to-value lookup.
A list preserves order and duplicates, whereas a set promises no iteration order. A dictionary preserves insertion order, and updating an existing key keeps its position.
Equal keys with the same hash share an entry, as the example shows for 1 and True.
Examples
labels = ["blue", "red", "blue"]
print(labels[2], len(set(labels)), list(dict.fromkeys(labels)))
values = {1: "first", 2: "next"}
values[True] = "updated"
print(list(values.items()))
Result
blue 2 ['blue', 'red'] [(1, 'updated'), (2, 'next')]
Equal keys with the same hash share an entry, as the example shows for 1 and True.