4 ms·
This is pretty cool, if we're porting JS features do we get dictionary unpacking/destructuring next? I just want this so badly, it's the main reason I drift ba
by nikisweeting 1y ago
This is pretty cool, if we're porting JS features do we get dictionary unpacking/destructuring next?
I just want this so badly, it's the main reason I drift back to JS:
>>> {a, b=45, c=None, **d} = {'a': 234, xzy: 32456}
>>> print(a, b, c, d)
234 45 None {'xyz': 32456}
- enragedcacti 1y agojust use this very sane pattern /s: >>> match {'b': 45, 'c': None}|{'a': 234, 'xyz': 32456}: >>> case {'a': a, 'b': b, 'c': c, **d}: pass >>> print(a, b, c, d) 234 45 None {'xyz': 32456}
- zahlman 1y agoAnother alternative: >>> a, b, c, d = (lambda a, b=45, c=None, **d: (a, b, c, d))(**{'a': 234, 'xyz': 32456}) The parentheses for this are admittedly a bit tricky.