[英]Sorting a list of publications by year
I'm am growing a list of publications authored by a specific person featured on Google Scholar, using scholarly PyPi module (pub in author.publications).我正在使用学术 PyPi 模块(在 author.publications 中发布)增加由 Google Scholar 上的特定人员撰写的出版物列表。
from scholarly import scholarly
search_query = scholarly.search_author('John Doe')
author = next(search_query).fill()
c = 0
list = []
Each line of the list comprises three items: 1- an iteration number using a counter,(c) 2- Title, 3- Year.列表的每一行包括三个项目:1- 使用计数器的迭代次数,(c) 2- 标题,3- 年。 The list can then be displayed by order of relevance (iteration number).
然后可以按相关顺序(迭代次数)显示该列表。
Once completed, I want to sort the list by release year.完成后,我想按发布年份对列表进行排序。 Here are two unsuccessful attempts as the list comes out in the same order it previously did (by relevance).
这里有两次不成功的尝试,因为列表以与之前相同的顺序出现(按相关性)。 If you're able to see what I did wrong... Thanks!
如果你能看到我做错了什么......谢谢!
ATTEMPT no.1尝试 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)
ATTEMPT no.2尝试 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
df.sort() method? have you tried this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.