AttributeError: ‘dict_keys‘ object has no attribute ‘remove‘

dic1 = {'a':1, 'b':2, 'c':3}
# keys = list(dic1)
keys = dic1.keys()
keys.remove('b')
print(keys)

报错

AttributeError: 'dict_keys' object has no attribute 'remove'

改为如下即可:

dic1 = {'a':1, 'b':2, 'c':3}
keys = list(dic1)
# keys = dic1.keys()
keys.remove('b')
print(keys)

输出:

['a', 'c']
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页