
28
|
Python Pocket Reference
adict.popitem()
Removes and returns an arbitrary (key, value) pair.
adict.pop(k [, x])
Returns adict[k] if k in adict (and removes k); else,
returns
x.
adict.fromkeys(seq [, value])
Creates a new dictionary with keys from seq and values
set to
value.
adict.iteritems(), adict.iterkeys(), adict.itervalues()
Returns an iterator over key/value pairs, keys only, or
values only.
Tuples
Tuples are immutable arrays of object references, accessed by
offset.
Literals
Tuples are written as comma-separated series of values
enclosed in parentheses. The enclosing parentheses can
sometimes be omitted (e.g., in
for loop headers and = assign-
ments).
()
An empty tuple.
(0,)
A one-item tuple (not a simple expression).
(0, 1, 2, 3)
A four-item tuple.
0, 1, 2, 3
Another four-item tuple (same as prior line); not valid in
function calls.
atuple = ('spam', (42, 'eggs'))
Nested tuples: atuple[1][1] fetches 'eggs'.