Last active
February 17, 2020 12:59
-
-
Save yozx/a1761ef5679905979ece2083463153bd to your computer and use it in GitHub Desktop.
compute over dict
This file contains hidden or 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
# 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