【问题标题】:Sorting a list of publications by year按年份对出版物列表进行排序
【发布时间】:2020-07-03 16:30:00
【问题描述】:

我正在使用学术 PyPi 模块(在 author.publications 中发布)增加由 Google Scholar 上的特定人员撰写的出版物列表。

from scholarly import scholarly

search_query = scholarly.search_author('John Doe')
author = next(search_query).fill()
c = 0
list = []

列表的每一行包含三个项目:1- 使用计数器的迭代次数,(c) 2- 标题,3- 年份。然后可以按相关顺序(迭代次数)显示该列表。

完成后,我想按发布年份对列表进行排序。这里有两次不成功的尝试,因为列表的出现顺序与之前的顺序相同(按相关性)。如果你能看到我做错了什么...谢谢!

第 1 次尝试

for pub in author.publications:
    try:
        c += 1                                                    # c = c + 1
        print(c, pub.bib['title'], '(', pub.bib['year'], ')')     # displayed in relevance order
        list.append([pub.bib['title'],pub.bib['year']])           # modifies/expands the list
        def get_year(list):
            return list.get(pub.bib['year'])
        list.sort(key=get_year)                                   # re-arrange the list by release year

    except:
        pass


for l in list:                                                    # should print each line of the new list, but instead displays the original
    print(l)

第 2 次尝试

for pub in author.publications:
    try:
        c += 1                                                     # c = c + 1
        print(c, pub.bib['title'], '(', pub.bib['year'], ')')      # displayed in relevance order 
        list.append([pub.bib['title'],pub.bib['year']])            # modifies/expands the list
        list.sort(key=[pub.bib['year']])                           # re-arrange the list by release year                                  

    except:
        pass

for l in list:
    print(l)                                                       # should print each line of the new list, but instead displays the original

【问题讨论】:

    标签: python sorting google-scholar


    【解决方案1】:
    df.sort() method? have you tried this
    

    【讨论】:

    • 如有任何澄清,请使用 cmets 不要发布作为答案。
    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 2018-10-01
    • 2023-04-01
    • 2013-02-12
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    相关资源
    最近更新 更多