Skip to content

Instantly share code, notes, and snippets.

@ishidur
Last active September 8, 2018 16:11
Show Gist options
  • Save ishidur/021b55417e9c1c66fcf3765135aac147 to your computer and use it in GitHub Desktop.
Save ishidur/021b55417e9c1c66fcf3765135aac147 to your computer and use it in GitHub Desktop.
PythonでDictionary型のValueにnoneがないかを判定 #code
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