Database 如何对数据库进行排序

Database 如何对数据库进行排序,database,sorting,python-3.x,Database,Sorting,Python 3.x,我有一个数据库,我现在使用这个函数组合 def ReadAndMerge(): library1=input("Enter 1st filename to read and merge:") with open(library1, 'r') as library1names: library1contents = library1names.read() library2=input("Enter 2nd filename to read and merg

我有一个数据库,我现在使用这个函数组合

def ReadAndMerge():
    library1=input("Enter 1st filename to read and merge:")
    with open(library1, 'r') as library1names:
        library1contents = library1names.read()
    library2=input("Enter 2nd filename to read and merge:")
    with open(library2, 'r') as library2names:
        library2contents = library2names.read()

    print(library1contents)
    print(library2contents)
    combined_contents = library1contents + library2contents  # concatenate text

    print(combined_contents)
    return(combined_contents)
这两个数据库最初是这样的

Bud Abbott 51 92.3
Mary Boyd 52 91.4
Hillary Clinton 50 82.1
Bud Abbott 51 92.3
Mary Boyd 52 91.4
Hillary Clinton 50 82.1
Don Adams 51 90.4
Jill Carney 53 76.3
Randy Newman 50 41.2
还有这个

Don Adams 51 90.4
Jill Carney 53 76.3
Randy Newman 50 41.2
经过组合后,它们现在看起来像这样

Bud Abbott 51 92.3
Mary Boyd 52 91.4
Hillary Clinton 50 82.1
Bud Abbott 51 92.3
Mary Boyd 52 91.4
Hillary Clinton 50 82.1
Don Adams 51 90.4
Jill Carney 53 76.3
Randy Newman 50 41.2
如果我想按姓氏对数据库进行排序,我会怎么做? 类似python的列表中是否内置了排序函数?这算是一份清单吗?
或者我必须使用另一个函数来定位姓氏,然后按字母顺序排序,您可以使用
sorted()
方法进行排序。但是你不能只对一个大字符串进行排序,你需要把数据放在一个列表或类似的东西中。类似这样(未经测试):


你在使用哪个数据库?我不知道我是否理解你的要求,我对编码是新手,所以如果我使用了错误的术语,我很抱歉。它们只是保存在我电脑上的.txt文件对不起,我的错,我以为你在使用数据库。我已经更新了我的回答虽然严格正确,但将包含数据的文件称为“数据库”会让大多数人感到困惑,因为“数据库”通常用于处理、索引和搜索大型数据集的软件。因此,您没有数据库。您只有一个包含数据的文件。更好的是,将这些行放入对象中。(名字:“巴德·阿伯特”,数字51,浮点数92.3)@crapman:这是下一步。走之前先爬,等等:-)你的答案把我的每一个字都分类了,它把我的一组名字和数字变成了这样['\n'、'\n'、'\n'、'\n'、'\n'、'\n'、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''、''还有更多,但不是全部fit@spenman:没有。您错过了从
read()
readlines()
的更改。