Title: Theory / Unimportant / CS / Programming / Python / Lib / built-in types / Dict
Tags: computer_to_instruction automatedNewLineAfterCommaSpace FromInstruction hasNotNewEffectReturnsMeaning some_instruction
On every note of this deck, unless a note says otherwise:
Page: https://docs.python.org/3.7/library/stdtypes.html#mapping-types-dict

Instruction: dict(key_1=val_1,...,key_n=val_n)
Page: https://docs.python.org/3.7/library/stdtypes.html#mapping-types-dict and expression page
Effect: The dictionnary associating key_i to val_i
Language: Python
Chapter: 6
Section: 2.6
Abbreviation: {key_1:val_1,...,key_n:val_n}

Instruction: dict(
  m,
  key_1=val_1,...,key_n=val_n
)
Effect: the dictionnary which is a copy of the mapping m, wich furthermore associate key_i to val_i.
Language: Python
Variables: m a mapping

Instruction: dict(
iter,
key_1=val_1,
...,
key_n=val_n
)
Effect: dict(key'_1=val'_1,...,key'_n'=val'_n', key_1=val_1,...,key_n=val_n) where (key'_i, val'_i') is the set of pairs in iter
Language: Python
Variables: iter an iterable
Assuming: iter contains only iterable of length 2

Instruction: d[key]
Effect: The value associated to key if it exists.
d.__missing__(key) if missing exists
raise KeyError otherwise
Language: Python
Variables: d a dictionnary

Instruction: dict.fromkeys(
  iter,
  value = None
)
Effect: A dictionnary whose keys are found in iter and associating each key to value
Language: Python

Instruction: d.get(key,default=None)
Language: Python
Returns: The value for key if key is in the dictionary, else default.
Variables: d a dict

Instruction: d.items()
Language: Python
Returns: a new view of the dictionary’s items ((key, value) pairs).
Variables: d a dict

Instruction: d.pop(key)
Effect: del d[key]
Language: Python
Returns: Return d[key]
Variables: d a dict
Example: KeyError if key not in d

Instruction: d.pop(key,default)
Effect: if key in d:
del d[key]
Language: Python
Returns: Return d.get(key,default)
Variables: d a dict

Instruction: d.popitem()
Effect: remove the last entry added to d and still in it
Language: Python
Returns: The last (key,value) pair added to d and still in it
Variables: d a dict
Example: KeyError if empty

Instruction: d.setdefault(key,default=None)
Effect: if key not in d:
d[key]=default
Language: Python
Returns: d.get(key,default)
Variables: d a dict

Instruction: d.update(m)
Effect: for key,val in (m or m.items):
d[key]=val
Language: Python
Variables: d a dict

Instruction: d.view()
Language: Python
Returns: View of dictionnary values
Variables: d a dict

Name: A view object for d
Definition: An object whose value change to reflect d change
Page: https://docs.python.org/3.7/library/stdtypes.html#mapping-types-dict
Variables: d a dict

Question: How are dict encoded
Answer: Hash table
Page: https://wiki.python.org/moin/TimeComplexity