python 合并两个字典

来源:互联网 发布:网络公开课英语作文 编辑:程序博客网 时间:2024/05/13 12:12

合并字典sentiment_dictpos_dictall_dict
方法一:最 pythonic 的方法

all_dict = {**sentiment_dict ,** pos_dict}

方法二:

all_dict = {k: v for d in [sentiment_dict , pos_dict] for k, v in d.items()}

方法三:最基础的方法

all_dict = {}all_dict .update(sentiment_dict )all_dict .update(pos_dict)

参考链接怎样合并字典最符合Python语言习惯?

0 0
原创粉丝点击