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

python dict list tuple

时间:2014-10-17 23:15:55      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:style   blog   sp   div   on   log   ef   bs   line   

Dict

创建

somedict = {}
somedict = {"key": value}

a = dict(one=1, two=2, three=3)
c = dict(zip([‘one‘, ‘two‘, ‘three‘], [1, 2, 3]))
d = dict([(‘two‘, 2), (‘one‘, 1), (‘three‘, 3)])

删除

del somedict["key"]
somedict.pop("key", default_value_if_key_not_exist)

添加

somedict["key"] = value

合并

somedict.update(anotherdict)

 

List

创建

x = [1,2,3]
x = list((1,2,3))

添加

x.append(value)

合并

x = [1, 2, 3]
y = [4, 5]
z = x + y
x.extend(y)

删除

x.remove(value)
x = x[0:i] + x[i + 1:]
del x[i]
del x[i:j]

 

python dict list tuple

标签:style   blog   sp   div   on   log   ef   bs   line   

原文地址:http://www.cnblogs.com/lailailai/p/4032188.html

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