按字母顺序对包含 2 条数据的列表进行排序

Sorting a list with 2 pieces of data alphabetically

整理出我的一个按分数排序的排序函数后,我现在需要让它按名字的第一个字母准确排序

文件中的数据如下所示:

Amber 0
Cyan 1
Blue 2

我试过这个:

with open("Scores.txt","r") as f:
    lines = sorted(f.readlines())
    print lines

这以一种奇怪的顺序给出了它。它从以 A 开头的名字开始,然后移到以 R 开头的名字,然后是 O。

我的输出需要是这样的:

Amber 0
Blue 2
Cyan 1

这是一个相对简单的程序,我使用的是Python 2.7

任何帮助都会很棒我也可以提供有关我的程序的任何信息!

试试这个,

with open("Scores.txt","r") as f:
    lists = [line.rstrip().split() for line in f.readlines()]
    lists.sort()
    print(lists)

# Output
[['Amber', '0'], ['Blue', '2'], ['Cyan', '1']]