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]