Skip to content

Instantly share code, notes, and snippets.

@mutaku
Last active December 25, 2015 00:59
Show Gist options
  • Save mutaku/6891963 to your computer and use it in GitHub Desktop.
Save mutaku/6891963 to your computer and use it in GitHub Desktop.
calculating h-indices
def h_index(pubs):
"""n-publicaions with at least n-citations"""
# sort the list of citations
pubs = sorted(pubs)
# iterate over the sorted list
for i, x in enumerate(pubs):
# number of citations including this one and greater
n = len(pubs[i:])
# if this citaiton index is greater than or equal to
# n, we have an h_index
if x >= n:
return n
return False
In [78]: pubs = [43, 77, 3, 32, 2, 32, 4]
In [79]: h_index(pubs)
Out[79]: 4
In [112]: h_index([800, 403, 420, 391])
Out[112]: 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment