Created
February 11, 2015 12:13
-
-
Save themalkolm/ea277d47cf0b2292ff5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@funcy.collecting | |
def unpack(*args): | |
d = args[-1] | |
for k in args[:-1] | |
yield d[k] | |
a, b = unpack('a', 'b', {'a': 1, 'b': 2, 'c': 3}) |
Author
themalkolm
commented
Feb 11, 2015
def unpack(*keys):
@funcy.collecting
def _unpack(d):
for k in keys:
yield d[k]
return _unpack
a, b = unpack('a', 'b')({'a': 1, 'b': 2, 'c': 3})
def unpack(*keys):
def _unpack(d):
return [d[k] for k in keys]
return _unpack
a, b = unpack('a', 'b')({'a': 1, 'b': 2, 'c': 3})
def unpack(*keys):
return lambda d: [d[k] for k in keys]
a, b = unpack('a', 'b')({'a': 1, 'b': 2, 'c': 3})
def dict_unpack(*keys):
"""Return dict unpacker for the provided keys in the exact order."""
return lambda d: [d[k] for k in keys]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment