python实现从字典中删除元素的方法
2015-05-04 00:00
816 查看
本文实例讲述了python实现从字典中删除元素的方法。分享给大家供大家参考。具体分析如下:
python的字典可以通过del方法进行元素删除,下面的代码详细演示了这一过程
希望本文所述对大家的Python程序设计有所帮助。
python的字典可以通过del方法进行元素删除,下面的代码详细演示了这一过程
# Create an empty dictionary d = {} # Add an item d["name"] = "Fido" assert d.has_key("name") # Delete the item del d["name"] assert not d.has_key("name") # Add a couple of items d["name"] = "Fido" d["type"] = "Dog" assert len(d) == 2 # Remove all items d.clear() assert len(d) == 0
希望本文所述对大家的Python程序设计有所帮助。
相关文章推荐
- python实现从字典中删除元素的方法
- Python简单遍历字典及删除元素的方法
- Python实现列表删除重复元素的三种常用方法分析
- Python实现连接两个无规则列表后删除重复元素并升序排序的方法
- Python 删除字典元素的4种方法
- python实现删除文件与目录的方法
- 构造一个特殊栈,实现方法getmin,返回栈中的最小元素 Python版
- Python实现字典按照value进行排序的方法分析
- python创建列表和向列表添加元素的实现方法
- python中List添加、删除元素的几种方法
- Python三种方法删除列表中的元素
- Java 基本数组删除特定元素的实现方法
- Python cookbook(数据结构与算法)找到最大或最小的N个元素实现方法示例
- Python cookbook(数据结构与算法)实现查找两个字典相同点的方法
- Python 字典删除元素clear、pop、popitem
- python中字典删除元素
- 统计元素个数+字典存入文件(通过序列化)的python实现
- 面试题---请写出一段Python代码实现删除一个list里面的重复元素
- Python实现变量数值交换及判断数组是否含有某个元素的方法
- Python有序字典简单实现方法示例