今天第一次发随笔还有许多不足之处,欢迎评论!!!

最近在写一个成语接龙的小游戏,结果在数组添加元素时报错: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的更多相关文章

  1. python报错IndexError: list index out of range

    今天写个ping vpn的python脚本,报错IndexError: list index out of range 最后查看是python读取文件中出现空格 去掉空格即可

  2. pyinstaller 将.py生成.exe ----报错 “IndexError: tuple index out of range”

    pyinstaller将py打包为exe文件,用pysintaller居然报错 File "c:\anaconda3\lib\site-packages\PyInstaller\depend ...

  3. xadmin 数据添加报错: IndexError: list index out of range

    报错现象 xadmin 集成到项目后进行添加数据的时候报错 具体如下 黄页 后端 具体报错定位 报错分析 点击这里 报错解决 源码 input_html = [ht for ht in super(A ...

  4. Python常见错误:IndexError: list index out of range

    用python写脚本查询字典时,在遍历字典时循环到某一项时老是报错   出现这种错误有两种情况: 第1种可能情况 list[index]index超出范围 第2种可能情况 list是空值就会出现 In ...

  5. IndexError:string index out of range

    IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界

  6. MacOS 安装MysqlDB 问题解决方案( 解决 IndexError: string index out of range)

    pip install MySQL-python时报错如下: Command "python setup.py egg_info" failed with error code 1 ...

  7. mac安装MySQLdb:IndexError: string index out of range

    使用mac安装MySQLdb的时候出现string index out of range 大概的错误是这样的: 然后尝试手动安装,我下载了包后,依然出现这个错误. 于是百度了下: https://ww ...

  8. 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 ...

  9. javaWeb项目加载HTML文件时报错 [No Find /index.html]

    直接上主题: 在web.xml文件中添加如下信息: <display-name>Spring MVC Application</display-name> <servle ...

随机推荐

  1. [暴力] Educational Codeforces Round 71 (Rated for Div. 2) B. Square Filling (1207B)

    题目:http://codeforces.com/contest/1207/problem/B   B. Square Filling time limit per test 1 second mem ...

  2. mongodb的增加和删除

    一  mongodb中使用insert()方法来增加集合中的文档: db.myTable.insert({name:'arvin',age:12}) //对名为myTable的集合插入数据 插入数据 ...

  3. C语言中结构体内存存储方式

    C语言中结构体内存存储方式 结构体的默认存储方式采用以最大字节元素字节数对其方式进行对齐,例如一个结构体中定义有char.int类型元素,则结构体存储空间按照int类型占用字节,如果还有double类 ...

  4. [POJ2533]Longest Ordered Subsequence<dp>

    题目链接:http://poj.org/problem?id=2533 描述: A numeric sequence of ai is ordered if a1 < a2 < ... & ...

  5. A换算时间(只想开学)HDU 6556

    题目链接 思路如下 把时间转化为 24小时制下进行考虑,首先我们要明白(在24小时制下):12 点表示是下午PM ,而 24点表示的是明天的 0点(12小时制下),这两个地方需要特殊考虑 题解如下 # ...

  6. 1047: 【入门】正整数N转换成一个二进制数

    1047: [入门]正整数N转换成一个二进制数 时间限制: 1 Sec 内存限制: 16 MB 提交: 9786 解决: 6447 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 输入 ...

  7. IO 流

    ------------恢复内容开始------------ 一.流的简介 输入流:把硬盘中的数据读取到内存中 输出流:把内存中的数据读取到硬盘中 1字符=2字节 1字节=8位 1.2顶级父类  二. ...

  8. (CSS):last-child与:last-of-type区别

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>la ...

  9. PTA数据结构与算法题目集(中文) 7-40奥运排行榜 (25 分)

    PTA数据结构与算法题目集(中文)  7-40奥运排行榜 (25 分) 7-40 奥运排行榜 (25 分)   每年奥运会各大媒体都会公布一个排行榜,但是细心的读者发现,不同国家的排行榜略有不同.比如 ...

  10. c期末笔记(1)

    运算符 1.i++与++i的细微区别 i++与++i 和i++放在一个语句中,则i原本的值先被利用.语句结束后,i的值加一. i的原始值失效,直接加一. 2.int加法 整形数据(int)加上任何类型 ...