Re:Python idiom for taking the single item from a list
by alrex021 on Monday September 27, 2010 @02:13PM
(#1732680)
There you have it folks, Python supports destructuring assignment. :-)
[ Parent
| on HN ]
Re:Python idiom for taking the single item from a list
by jerf on Monday September 27, 2010 @02:43PM
(#1732823)
What's the smiley for?
Python 2.6.5...
Type "help", "copyright", "credits" or "license" for more information.
>>> (a, (b, c, (d, e))) = (1, (2, 3, (4, 5)))
>>> a, b, c, d, e
(1, 2, 3, 4, 5)
>>> (a, (b, c, (d, e))) = (1, (2, 3, (4, 5, 6)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
It isn't quite as flexible as functional languages and it's not as idiomatic as it is in functional languages, but it's not a hack or quirky edge-case either.