Skip to content

Instantly share code, notes, and snippets.

@migonzalvar
Created May 27, 2015 10:14
Show Gist options
  • Save migonzalvar/12579d0533d07df0fa53 to your computer and use it in GitHub Desktop.
Save migonzalvar/12579d0533d07df0fa53 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Use of a callable to implement lazy evaluation of keys in a dict."""
data = {
'name': 'John',
'surname': 'Smith',
'full_name': lambda x: '{name} {surname}'.format(**x)
}
if __name__ == '__main__':
print(data)
for k, v in data.items():
if callable(v):
data[k] = v(data)
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment