Last active
September 8, 2018 16:11
-
-
Save ishidur/021b55417e9c1c66fcf3765135aac147 to your computer and use it in GitHub Desktop.
PythonでDictionary型のValueにnoneがないかを判定 #code
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
def NoneCheckDict(dictionary): | |
return list(map(lambda key: ('parameter \'%s\' is None' % key), | |
filter(lambda key: dictionary[key] is None, dictionary.keys()))) | |
if __name__ == '__main__': | |
# non None value | |
params = { | |
'aaa': 111, | |
'bbb': 222, | |
'ccc': 333 | |
} | |
err = NoneCheckDict(params) | |
print(err) | |
# Output: [] | |
print(bool(err)) | |
# Output: False - no error | |
# including None value | |
params1 = { | |
'aaa': None, | |
'bbb': None, | |
'ccc': 333 | |
} | |
err = NoneCheckDict(params1) | |
print(err) | |
# Output: ['parameter 'aaa' is None', 'parameter 'bbb' is None'] | |
print(bool(err)) | |
# Output: True - error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment