Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
文本文件中的Python数字排序_Python - Fatal编程技术网

文本文件中的Python数字排序

文本文件中的Python数字排序,python,Python,嗨,我正在制作一个小游戏,它将用户完成游戏所花费的时间存储为他们的分数。我可以将分数附加到我的文本文件中,但我未能对它们进行排序 例如: 17.25詹森 18.5西蒙 20.12本 def scoring(): #appending level 1 score L1=[] L1.append((Timetaken,myname)) with open('L1.txt','a') as x: x.write('%f,%s'%(Timetaken,my

嗨,我正在制作一个小游戏,它将用户完成游戏所花费的时间存储为他们的分数。我可以将分数附加到我的文本文件中,但我未能对它们进行排序

例如: 17.25詹森 18.5西蒙 20.12本

def scoring():
    #appending level 1 score
    L1=[]
    L1.append((Timetaken,myname))
    with open('L1.txt','a') as x:
        x.write('%f,%s'%(Timetaken,myname))
def arranging():
    #Sorting level 1
    column=[]
    with open('L1.txt') as file1:
        for line in file1:
            column.append(line.split('\n'))
    sorted(column,key=itemgetter(0),reverse=False)
    with open("L1.txt",'w+') as first:
        for x in column:
            if (len(column))<=10:
            first.write(str(x)+str(' , '))`
def评分():
#附加1级分数
L1=[]
L1.追加((耗时,myname))
以open('L1.txt','a')作为x:
x、 写入(“%f,%s%”(耗时,myname))
def():
#排序级别1
列=[]
打开('L1.txt')作为文件1:
对于文件1中的行:
column.append(line.split('\n'))
已排序(列,键=itemgetter(0),反向=False)
以open(“L1.txt”,“w+”)作为第一个:
对于列中的x:
如果(len(column))您的问题是sorted()没有正确排序。您需要执行以下操作:

column = sorted(column,key=itemgetter(0),reverse=False)

如果你创建一个例子,你会得到更多更好的答案。尤其要确保输入的和预期的测试数据是完整的(不是伪数据),并且可以很容易地剪切和粘贴到编辑器中,以便测试建议的解决方案。什么是
所用的时间
?请出示球员的得分时间