Python 字典操作
Posted Sky_Liao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 字典操作相关的知识,希望对你有一定的参考价值。
字典合并:
1 >>>a_dict = {‘sky‘: ‘asdf‘, ‘liao‘: ‘asdf‘} 2 >>> a_dict 3 {‘sky‘: ‘asdf‘, ‘liao‘: ‘asdf‘} 4 >>> b_dict = {‘xiong‘: ‘asdf‘, ‘asky‘: ‘asdf‘} 5 >>> b_dict 6 {‘xiong‘: ‘asdf‘, ‘asky‘: ‘asdf‘} 7 >>> c_dict = dict(a_dict, **b_dict) 8 >>> c_dict 9 {‘sky‘: ‘asdf‘, ‘liao‘: ‘asdf‘, ‘xiong‘: ‘asdf‘, ‘asky‘: ‘asdf‘}
1 >>> a_dict = {‘sky‘: ‘asdf‘, ‘liao‘: ‘asdf‘} 2 >>> a_dict 3 {‘sky‘: ‘asdf‘, ‘liao‘: ‘asdf‘} 4 >>> b_dict = {‘xiong‘: ‘asdf‘, ‘asky‘: ‘asdf‘} 5 >>> b_dict 6 {‘xiong‘: ‘asdf‘, ‘asky‘: ‘asdf‘} 7 >>> c_dict = a_dict.copy() 8 >>> c_dict.update(b_dict) 9 >>> c_dict 10 {‘sky‘: ‘asdf‘, ‘liao‘: ‘asdf‘, ‘xiong‘: ‘asdf‘, ‘asky‘: ‘asdf‘} 11 >>>
以上是关于Python 字典操作的主要内容,如果未能解决你的问题,请参考以下文章