One HUGE distinction between dict unpacking and sequence unpacking is futureproofing. Suppose you have this function:
def interpret_color(color):
"""Figure out what a colo[u]r name means"""
# parse all the different things you might want
return 102, 51, 153
r, g, b = interpret_color("rebeccapurple")
There’s only one direction to safely extend this, and that’s at the right hand edge. Also, in order to be extensible at all, callers have to use it like this:
r, g, b, *_ = interpret_color("rebeccapurple")
In this particular example, it wouldn’t be a problem to extend to the right (the most obvious extension being an alpha
value), but you can’t always know that in advance, and callers still have to plan for the possibility that it returns more values in the future.
With dict unpacking, it would be far easier. The initial version would return {"r": 102, "g": 51, "b": 153}
, you unpack it into r/g/b, and all’s well. Yes, you have to unpack into those exact names, but in practice, that isn’t actually that big a limitation (can attest - have used this exact concept very frequently). And if an alpha channel is added? No problem, just have four things in the dictionary. No code needs to be changed. You could even insert it somewhere in the middle without a problem.
Obviously that’s not to say that dict unpacking is perfect, problem-free, and the ultimate replacement to sequence unpacking. But they have different tradeoffs, and having both in the language would be valuable.