Python中文
首页
教程
问答
标签
搜索
登录
注册
“int”和“str”实例之间不支持Python“<”
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>嗨,我是新来的编码,我刚刚开始。我见过许多相同错误的例子,但我不确定如何将其应用到我的代码中。我正在尝试按分数的顺序对文本文件进行排序。这是我当前的代码:</p> <pre><code>ScoresFile = open("Top Scores.txt","r") newScoresRec = [] ScoresRec = [] for row in ScoresFile: ScoresRec = row.split(",") username = ScoresRec[0] Bestscores = int(ScoresRec[1]) newScoresRec.append(username) newScoresRec.append(Bestscores) ScoresRec.append(newScoresRec) newScoresRec = [] sortedTable = sorted(ScoresRec,key=lambda x:x[1]) for n in range (len(sortedTable)): print(sortedTable[n][0],sortedTable[n][1]) ScoresFile.close() </code></pre> <p>文本文件仅采用以下简单格式:</p> <p>“用户名”,“分数”- 示例:BO15,78 任何帮助都将不胜感激</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>问题的一部分是您正在将其追加到拆分列表中</p> <pre><code>ScoresRec = row.split(",") ... ScoresRec.append(newScoresRec) </code></pre> <p>不建立清单清单,;在循环结束时,您将使用添加的两个附加值对文件的最后一行进行排序</p> <p>因此,您正在对包含几个字符串和一个列表的列表进行排序,排序键是一个包含字符串和int的列表,因此会出现错误</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何为此数据帧创建散点图?
2 回答
如何为此编写Django模板
2 回答
如何为此表达式编写正则表达式?
7 回答
如何为步进电机选择合适的值?
5 回答
如何为每15分钟间隔的日期时间行(在新列中)添加标签?
6 回答
如何为每一列创建汇总表?
10 回答
如何为每一组groupbyPandas做滚动“得到假人”
2 回答
如何为每一行分别运行函数(python)?
5 回答
如何为每一行生成一个随机数?
6 回答
如何为每一轮将pytorch模型输出存储到numpy
2 回答
如何为每个.py-fi文件创建单独的zip文件
5 回答
如何为每个<li class=”“><a>找到最近的上述同级<li>?
9 回答
如何为每个CSV列生成特定的文件?
8 回答
如何为每个csv文件使用read_csv,即使它是空的?PythonPandas
7 回答
如何为每个CSV文件创建单独的Pandas数据帧并给它们起有意义的名称?
7 回答
如何为每个datetime和每个id创建一行?
7 回答
如何为每个Django型号选择赋予不同的颜色
1 回答
如何为每个Django模型实例安排一个周期性的芹菜任务?
2 回答
如何为每个Django视图设置一个装饰器?
3 回答
如何为每个for循环迭代分配变量
6 回答