我正在使用学术 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