all examples return the same dictionary
a = {'one': 1, 'two': 2, 'three': 3}
comma-separated list of key: value
pairs, within braces
b = {'two': 2, 'three': 3, 'one': 1,} # ordine non conta c = dict(a)
d = dict(one=1, two=2, three=3)
e = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
f = dict([('one', 1), ('two', 2), ('three', 3)])
a == b == c == d == e == f True
list({'c':5,'a':2,'b':4}) ['c', 'a', 'b']
la lista di un dizionario e' la lista delle chiavi, i valori non sono considerati.
Per creare la lista dei valori
{'c':5,'a':2,'b':4}.values() dict_values([5, 2, 4])
same indexing syntax used for lists
nr['two'] # read value by key # Raises a KeyError if key not in map. nr['ten'] = 10 # Set a new key:value pair
class cnt(dict): def __missing__(self, key): return 0
crea il comportamento di collections.Counter([iterable-or-mapping])