iPython (easy_install ipython), , ? dir:
In [2]: dir {}
------> dir({})
Out[2]:
['__class__',
...
'keys',
'pop',
'popitem',
'setdefault',
'update',
'values']
In [3]: {}.update?
Type: dict
Base Class: <type 'dict'>
String Form: {}
Namespace: Interactive
Length: 0
Docstring:
dict() -> new empty dictionary.
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs.
dict(seq) -> new dictionary initialized as if via:
d = {}
for k, v in seq:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
(,)
, , : , (, set?), :
common_keys = [k for k in dict1 if k in dict2]
(.. " k dict1, dict2" )
( , O (1), O (| dict1 |))
edit: , dicts ... Lott , setdefault :
new = {}
for (k, v) in dict1.items():
new.setdefault(k, []).append(v)
for (k, v) in dict2.items():
new.setdefault(k, []).append(v)