|
The reason why Python works the way it does is specifically to keep the magical syntax as simple as possible. Consider the following: menu = [("Apples", 5),
("Cream Pie", 2),
("Tea and scones", 3)]
for food, price in menu:
print "To buy %s, please pay %d dollars" % (food,price)
Right now, it works unambiguously -- just the way you'd expect. The above prints: To buy Apples, please pay 5 dollars.
To buy Cream Pie, please pay 2 dollars.
To buy Tea and scones, please pay 3 dollars.
What if we implemented your rule? Would the intprereter print the above, or would it say this? To buy 0, please pay ("Apples", 5) dollars.
To buy 1, please pay ("Cream Pie", 2) dollars.
To buy 2, please pay ("Tea and scones", 3) dollars.
What if you wanted to print the first one? If your syntax were implemented, the programmer would have to write something awful like for index, (food, price) in menu:
or even for food, price in destructuring_without_index(menu):
which puts us in full circle again!The reason why most of us don't like your idea is because it introduces ambiguity and doesn't even remove the trade-off. No matter how you implement it, there's going to be a trade-off. The zen of python, by Tim Peters: Explicit is better than implicit.
Special cases aren't special enough to break the rules.
In the face of ambiguity, refuse the temptation to guess.
|