小编Mar*_*sch的帖子

删除Python中列表的最后一个元素失败

我正在尝试删除Python中列表的最后一个元素:

di = {"a": 3, "children": [{"b": 5}, {"c": 6}]}
for el in di['children']:
  di['children'].remove(el)
Run Code Online (Sandbox Code Playgroud)

我期待的是

print di
{'a': 3, 'children: []}
Run Code Online (Sandbox Code Playgroud)

但我得到的是

print di
{'a': 3, 'children': [{'c': 6}]}
Run Code Online (Sandbox Code Playgroud)

有人知道出了什么问题吗?

python dictionary list

4
推荐指数
3
解决办法
304
查看次数

标签 统计

dictionary ×1

list ×1

python ×1