1 // 2 == 0 is explicit floor division.
from __future__ import division enables "true division": 1 / 2 == 0.5.
Standard library already clean for -Qnew mode.
[*] | Bad idea to introduce a feature in a minor version, especially since it's an incomplete feature. Enough code ended up testing for it :-(. Strong policy of no features in minor versions since. |
Python sets module: sets.Set(), sets.ImmutableSet(). Supports boolean algebra operations.
dict.fromkeys(keys, value=None) builds set-like dicts.
sorted(iterable) returns new sorted list.
Keyword arguments cmp, key, reverse make common cases easier.
operator.attrgetter() and operator.itemgetter() handy as key functions.
min() and max() gain key arguments.
operator.attrgetter() and operator.itemgetter() support multiple arguments (return tuples).
PEP 328: Multi-line Imports
PEP 328: Absolute/Relative Imports: from __future__ import absolute_import stops looking relative to current __file__ unless the import is explicitly relative (from .dir import module).
New iterable.__iter__() protocol returning an iterator that has iterator.next() until it raises StopIteration. New iter() builtin. for loop now uses this protocol. So do many constructors (e.g. list() and functions (e.g. max).
Iterators for builtin types: files (lines), sequences, dicts (keys).
itertools module with things like chain, ifilter, izip.
enumarate(["a", "b", "c"]) yields (0, "a"), (1, "b"), (2, "c")
PEP 322: Reverse Iteration: for i in reversed(sequence).
PEP 323: Copyable Iterators: iterator.__copy__(), itertools.tee().
Cleanup after iteration: iterator.close(), iterator.throw(exc).
Co-routines: iterator.send(value) instead of iterator.next().
yield responds to generator.close() and generator.throw(). Can now yield inside try..finally.
yield is an expression, responds to generator.send(value).
Note: property() still not handled cleanly, metaclasses still ugly black magic. This is a very open field.
with statement to abstract enter-exit patterns.
Will have it's own __enter__()/__exit__() protocol but a standard decorator would wrap generators as with context functions.