排序列表按年份降序,如果记录具有相同年份,则按字母顺序排序

时间:2019-02-05 15:32:21

标签: python-3.x sortedlist

我很想做一个程序,该程序将打印按年份降序排列的列表,但是如果某些记录具有相同的年份,则需要按字母顺序对它们进行额外的排序。实际上是按年降序对打印记录进行编程。

def get_date_ordered(file_name):
    """
    file_name structure: Title, Total Copies, Year, Genre, Publisher
    """
    file_name = read_from_file()
    date = []
    list_of_title = [records[0] for records in file_name]
    title_alphabetical = sorted(list_of_title)
    records_descending = []
    for records in file_name:
            if records[2] not in date:
                    date.append(records[2])
    date_descending = (sorted(date, reverse=True))
    for i in range(len(date_descending)):
            for records in file_name:
                    if records[2] == date_descending[i]:
                            records_descending.append(records[0])
    print(records_descending)

0 个答案:

没有答案