# -*- coding:utf-8 -*- """ 作者:wangxingchun 日期:2022年03月28日 列表、字典的循环删除。 """ # 列表的循环删除方法,要求:删除姓王的数据 lst = ["李四", "王一", "王二", "王三", "张三"] tem = [] for item in lst: if item.startswith("王"): tem.append(item) for it in tem: lst.remove(it) print(lst) #字典的循环删除。要求:删除下面字典中姓王的数据。 dic = {"李四":"唱歌", "王一":"跳舞", "王二":"弹琴", "王三":"伴奏", "张三":"看书"} tem = [] for key in dic: if key.startswith("王"): tem.append(key) for k in tem: dic.pop(k) print(dic)