Delete None values from Python dict

前端 未结 2 1939
轻奢々
轻奢々 2021-02-08 20:47

Newbie to Python, so this may seem silly.

I have two dicts:

default = {\'a\': \'alpha\', \'b\': \'beta\', \'g\': \'Gamma\'}
user = {\'a\': \'NewAlpha\',          


        
2条回答
  •  心在旅途
    2021-02-08 21:13

    result = default.copy()
    result.update((k, v) for k, v in user.iteritems() if v is not None)
    

提交回复
热议问题