Skip to content

Instantly share code, notes, and snippets.

@hamaguchi-amago
Created July 7, 2021 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamaguchi-amago/ae994bfea27dcb23217c504aacaa42eb to your computer and use it in GitHub Desktop.
Save hamaguchi-amago/ae994bfea27dcb23217c504aacaa42eb to your computer and use it in GitHub Desktop.
dictからNoneのKeyを削除するサンプル
dict1 = {'key1': 'value1',
'key2': None,
'key3': 'value3',
'key4': None,
'key5': 'value5'}
dict1 = {k: v for k, v in dict1.items() if v is not None}
print(dict1)
@hamaguchi-amago
Copy link
Author

ブログの記事で作成しました。
興味のある方はご覧ください。

【Python】辞書(dict)からNoneを削除する方法
https://neko-py.com/python-dict-none-delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment