按年份对出版物列表进行排序
Sorting a list of publications by year
我正在使用学术 PyPi 模块(author.publications 中的 pub)增加由 Google 学者上的特定人员撰写的出版物列表。
from scholarly import scholarly
search_query = scholarly.search_author('John Doe')
author = next(search_query).fill()
c = 0
list = []
列表的每一行包含三个项目:1- 使用计数器的迭代次数,(c) 2- 标题,3- 年。然后可以按相关顺序(迭代次数)显示列表。
完成后,我想按发布年份对列表进行排序。这是两次不成功的尝试,因为列表的出现顺序与之前相同(按相关性)。如果你能看出我做错了什么...谢谢!
第一次尝试
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
df.sort() method? have you tried this
我正在使用学术 PyPi 模块(author.publications 中的 pub)增加由 Google 学者上的特定人员撰写的出版物列表。
from scholarly import scholarly
search_query = scholarly.search_author('John Doe')
author = next(search_query).fill()
c = 0
list = []
列表的每一行包含三个项目:1- 使用计数器的迭代次数,(c) 2- 标题,3- 年。然后可以按相关顺序(迭代次数)显示列表。
完成后,我想按发布年份对列表进行排序。这是两次不成功的尝试,因为列表的出现顺序与之前相同(按相关性)。如果你能看出我做错了什么...谢谢!
第一次尝试
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
df.sort() method? have you tried this