Pythonification of the asterisk-based collection packing/unpacking syntax
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Dec 25 07:45:22 EST 2011
On Sat, 24 Dec 2011 06:54:07 -0800, Eelco wrote:
> Context dependence is not something to be avoided at all costs, but all
> else being equal, less is certainly more. The general concept of
> grouping thing together which parenthesis is an extremely pervasive one
> in programming, and thus deserves its own set of context-dependent
> rules. Packing and unpacking collections is far, far more rare,
Not in Python, where it is a very common idiom.
> and thus
> a form that requires you to write more but remember less is certainly
> relatively favorable.
Not in Python, where iteration is a fundamental idiom and packing/
unpacking is a basic syntax construct precisely because the designer of
the language expects it to be common and encourages its use. There are
built-in functions designed to be used with unpacking operations, e.g.
enumerate and zip:
for i, obj in enumerate(sequence): ...
for a, b in zip(obj, range(100)): ...
--
Steven
More information about the Python-list
mailing list