Skip to content

Instantly share code, notes, and snippets.

@yozx
Last active February 17, 2020 12:59
Show Gist options
  • Save yozx/a1761ef5679905979ece2083463153bd to your computer and use it in GitHub Desktop.
Save yozx/a1761ef5679905979ece2083463153bd to your computer and use it in GitHub Desktop.
compute over dict
# generate data
data = {f'p_{_}': _ * 2 for _ in range(0, 16, 2)}
def compute(data, verbose=False):
condition = 'v*2 > 9'
result = {k: (v * 2 - 9, f'{v * 2} ({v}*2) > 9 {eval(condition)}')
if eval(condition) else (v * 2, False) for (k, v) in data.items()}
if not verbose:
return {k: v[0] for (k, v) in result.items()}
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment