在数组添加元素时报错:IndexError: list index out of range
今天第一次发随笔还有许多不足之处,欢迎评论!!!
最近在写一个成语接龙的小游戏,结果在数组添加元素时报错:IndexError: list index out of range
源码:
import pypinyin robot=[""] #机器回答的成语列表(先不加成语) robotpy1=[] #机器回答成语列表的所有成语的第一个拼音
for k in robot:#便利
robotpy1.append(pypinyin.pinyin(k, style=pypinyin.NORMAL)[0])#转换为拼音添加到robotpy1
结果 robotpy1.append(pypinyin.pinyin(k, style=pypinyin.NORMAL)[0]) 报错:IndexError: list index out of range
后来发现把 robot=[""] 改成 robot=["哀鸿遍野"] (主要是pypinyin不能转换空的)即可
更改后:
import pypinyin robot=["哀鸿遍野"] robotpy1=[]
for k in robot:
robotpy1.append(pypinyin.pinyin(k, style=pypinyin.NORMAL)[0])
robot=[""]
在数组添加元素时报错:IndexError: list index out of range的更多相关文章
- python报错IndexError: list index out of range
今天写个ping vpn的python脚本,报错IndexError: list index out of range 最后查看是python读取文件中出现空格 去掉空格即可
- pyinstaller 将.py生成.exe ----报错 “IndexError: tuple index out of range”
pyinstaller将py打包为exe文件,用pysintaller居然报错 File "c:\anaconda3\lib\site-packages\PyInstaller\depend ...
- xadmin 数据添加报错: IndexError: list index out of range
报错现象 xadmin 集成到项目后进行添加数据的时候报错 具体如下 黄页 后端 具体报错定位 报错分析 点击这里 报错解决 源码 input_html = [ht for ht in super(A ...
- Python常见错误:IndexError: list index out of range
用python写脚本查询字典时,在遍历字典时循环到某一项时老是报错 出现这种错误有两种情况: 第1种可能情况 list[index]index超出范围 第2种可能情况 list是空值就会出现 In ...
- IndexError:string index out of range
IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界
- MacOS 安装MysqlDB 问题解决方案( 解决 IndexError: string index out of range)
pip install MySQL-python时报错如下: Command "python setup.py egg_info" failed with error code 1 ...
- mac安装MySQLdb:IndexError: string index out of range
使用mac安装MySQLdb的时候出现string index out of range 大概的错误是这样的: 然后尝试手动安装,我下载了包后,依然出现这个错误. 于是百度了下: https://ww ...
- Mac安装Mysql-python遇到的坑,被这俩报错反复摩擦:'my_config.h' file not found 和 IndexError: string index out of range
最后Stackoverflow上面的大神解决了问题: Link brew install mysql brew unlink mysql brew install mysql-connector-c ...
- javaWeb项目加载HTML文件时报错 [No Find /index.html]
直接上主题: 在web.xml文件中添加如下信息: <display-name>Spring MVC Application</display-name> <servle ...
随机推荐
- 表格的删除与添加以及id的唯一性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- leetcode 945. 使数组唯一的最小增量
题目 给定整数数组 A,每次 move 操作将会选择任意 A[i],并将其递增 1. 返回使 A 中的每个值都是唯一的最少操作次数. 示例 1: 输入:[1,2,2] 输出:1 解释:经过一次 mov ...
- PyTorch1.2.0版本来啦!居然还有全套视频!让你快速熟练掌握深度学习框架!
[翻到文末, 还能让你看尽CV和NLP完整技术路径以及前沿+经典论文篇目,助你构建深度学习知识框架] 今年8月!PyTorch 1.2.0 版本来啦!! 据我们了解,在学术领域,特别是CV/NLP方向 ...
- PHP7内核(六):变量之zval
记得网上流传甚广的段子"PHP是世界上最好的语言",暂且不去讨论是否言过其实,但至少PHP确实有独特优势的,比如它的弱类型,即只需要$符号即可声明变量,使得PHP入手门槛极低,成为 ...
- coding++:Idea设置Java类注释模板和方法注释模板
设置类注释模板 1):选择File–>Settings–>Editor–>File and Code Templates–>Includes–>File Header. ...
- c#的全局异常捕获
以下操作在Program.cs中 1.最简单的方式try...catch.. 一般用在某一段容易出错的代码,如果用在整个软件排查,如下所示 static void Main() { try { App ...
- POJ 1163 数字三角形
Portal:http://poj.org/problem?id=1163 DP经典题,IOI94考题,在各大OJ上都有 #include<iostream> #include<al ...
- Java – Try with Resources
1.介绍 Java 7中引入的对try-with-resources的支持使我们能够声明将在try块中使用的资源,并确保在执行该块后将关闭资源. ⚠️:声明的资源必须实现AutoCloseable接口 ...
- ViewResolver视图解析器简单介绍
导言:同学们有没有想过这样一个问题,就是客户端每次请求之后,Spring MVC是怎么把请求响应成一个视图的?相信很多同学清楚如何使用,却不清楚Spring MVC里面是如何返回视图,那么,今天我们就 ...
- SpringMVC(四):数据处理和过滤器
本文是按照狂神说的教学视频学习的笔记,强力推荐,教学深入浅出一遍就懂!b站搜索狂神说或点击下面链接 https://space.bilibili.com/95256449?spm_id_from=33 ...