Created
January 18, 2018 21:27
-
-
Save chartjes/3aeffbd593be3e40daa1d8fcc1937c63 to your computer and use it in GitHub Desktop.
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
''' | |
bug_data is a dict like {'product': 'Cloud Services', 'version': 'Unspecified'} | |
Is there a better way to do look for specific keys in that dict so I can say | |
"You are missing one of the default fields | |
''' | |
if 'product' not in bug_data: | |
return "Missing 'product' field" | |
elif 'component' not in bug_data: | |
return "Missing 'component' field" | |
elif 'summary' not in bug_data: | |
return "Missing 'summary' field" | |
elif 'version' not in bug_data: | |
return "Missing 'version' field" |
required = {'product', 'component', 'summary', 'version'}
bug_data = {'product': 'Cloud Services', 'version': 'Unspecified'}
diff = required.difference(bug_data)
if diff:
print('Missing ' + ', '.join(diff) + ' field(s)')
I like @rlittlefield's answer but how about: print('Missing {} field(s)'.format(', '.join(diff)))
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@chartjes
or