Comment by andy99
2 days ago
def u(**kwargs):
return tuple(kwargs.values())
Am I missing something, is this effectively the same?
*I realize the tuple can be omitted here
2 days ago
def u(**kwargs):
return tuple(kwargs.values())
Am I missing something, is this effectively the same?
*I realize the tuple can be omitted here
You have to pull them out by key name, and not just get everything. Here's a working version, though with a totally different syntax (to avoid having to list the keys twice, once as keys and once as resulting variable names):
Modifying locals() is generally frowned upon, as there's no guarantee it'll work. But it does for this example.
Or use itemgetter:
Ohhh, nice. Also, attrgetter (which also supports dotted notation to get nested attrs! Sadly, no dotted notation for itemgetter.)
https://docs.python.org/3/library/operator.html#operator.att...
There are so many things like this one in the standard library that it kinda pisses me off when I discover a new one.
Yours relies on ordering, OP's presumably does not.
TFA looks things up by key, and allows pulling a subset of the dict.