码迷,mamicode.com
首页 > 编程语言 > 详细

Python 字典操作

时间:2018-05-16 13:01:21      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:sed   isp   bae   div   技术分享   upd   date   hid   sky   

字典合并:

技术分享图片
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 字典操作

标签:sed   isp   bae   div   技术分享   upd   date   hid   sky   

原文地址:https://www.cnblogs.com/skyliao/p/9044873.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!