Python 3.x Python排序

Python 3.x Python排序,python-3.x,Python 3.x,因此,我知道如何导入texfile并对数字进行排序,例如: 1 6 4 6 9 3 5 但我不知道如何对如下数据进行排序: Merchant_9976 20122 Merchant_9977 91840 Merchant_9978 92739 Merchant_9979 97252 Merchant_9980 76885 Merchant_9981 67835 Merchant_9982 42201 Merchant_9983 47463 这是到目前为止我的代码 import time

因此,我知道如何导入texfile并对数字进行排序,例如:

1
6
4
6
9
3
5
但我不知道如何对如下数据进行排序:

Merchant_9976 20122
Merchant_9977 91840
Merchant_9978 92739
Merchant_9979 97252
Merchant_9980 76885
Merchant_9981 67835
Merchant_9982 42201
Merchant_9983 47463
这是到目前为止我的代码

   import time


def sort_slow(seq):
    """
    :param seq:
    :return:
    """
    for i in range(1, len(seq)):
        j = i
        while j > 0 and seq[j - 1] > seq[j]:
            seq[j - 1], seq[j] = seq[j], seq[j - 1]
            j -= 1
    return seq


def main():
    fileName = str(input('Please enter a filename: '))
    file = open(fileName)
    sort1 = []
    for lines in file:
        sort1.append(int(lines.strip()))
    #a = [3, 5, 2, 1, 10]
    starting = time.clock()
    print(starting)
    sort_slow(sort1)
    print(sort1)
    #print(sort_slow([a]))
    #print(sort_slow(a))
    elapsed = time.clock() - starting
    print(elapsed)


main()
ar
包含文件中按第二列排序的所有行

lines = file.readlines()
ar = map( lambda x: x.split(), lines )
ar = ar.sort(key=lambda x: x[1])