TypeError: 'dict_keys' object does not support indexing
来源:互联网 发布:发现旅行靠谱吗 知乎 编辑:程序博客网 时间:2024/05/18 00:44
- import random
- outcomes = {’heads’:0, ‘tails’:0}
- sides = outcomes.keys()
- print(sides[0])
import randomoutcomes = {'heads':0, 'tails':0}sides = outcomes.keys()print(sides[0])
会产生错误:TypeError: ‘dict_keys’ object does not support indexing
这是由于python3改变了dict.keys,返回的是dict_keys对象,支持iterable 但不支持indexable,我们可以将其明确的转化成list:
- import random
- outcomes = {’heads’:0, ‘tails’:0}
- sides = list(outcomes.keys())
- print(sides[0]) # 输出tails
import randomoutcomes = {'heads':0, 'tails':0}sides = list(outcomes.keys())print(sides[0]) # 输出tails
阅读全文
0 0
- TypeError: 'dict_keys' object does not support indexing
- TypeError: 'dict_keys' object does not support indexing
- TypeError: 'dict_keys' object does not support indexing
- TypeError: 'dict_keys' object does not support indexing
- TypeError: 'dict_keys' object does not support indexing
- python提示错误TypeError: 'dict_keys' object does not support indexing
- python3.6 TypeError: 'dict_keys' object does not support indexing
- Strange SQLAlchemy error message: TypeError: 'dict' object does not support indexing
- “TypeError: 'dict_keys' object is not subscriptable”
- TypeError: 'ItemMeta' object does not support item assignment
- TypeError: 'str' object does not support item assignment 的解决方法
- python 报错TypeError: 'range' object does not support item assignment,解决方法
- theano 中出现 TypeError: 'TensorVariable' object does not support item assignment
- AccessDecisionManager does not support secure object class
- python object does not support item assignment
- TypeError:'str' does not support the buffer interface
- TypeError:’str’ does not support the buffer interface
- Python 3 TypeError: ‘str’ does not support the buffer interface
- opencv配置时cmake失败
- undefined is not a function错误解决
- HDU 5821 Ball 思路题
- 使用JSCore- iOS 原生的框架实现js和oc混编
- spring上传图片到web服务器
- TypeError: 'dict_keys' object does not support indexing
- python open() 文件解码问题
- JSP
- 每天一个linux命令(24):文件权限命令 chown命令
- ios-监听键盘的弹起事件
- 数据结构链表 --头节点链表复习
- Glide 缓存策略 内存缓存和磁盘缓存
- 2016本科论文节选
- Java设计模式-建造者模式(2)