[snip]
Provided you don't change the order of the items in the tuple, you can
just use slicing:

a, b = f()[ : 2]

Yes, this is what you would normally do with tuples. But i find this syntax very implicit and awkward. Also, you cannot skip elements, so you often end up with things like
a, _, b = f()[:3]

The use case I posted is just the most recent that I stumbled upon. But often a project function would have saved me a lot of typing. Consider for example when named tuples are used for rows in an ORM (or attributes in XML):

for person in people:
        name, age, address = person['name age address']
        # code






--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to