python dict list tuple

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]

 

posted @ 2014-10-17 22:21  卖程序的小歪  阅读(271)  评论(0编辑  收藏  举报