L-Factor

Compute your L-Factor: the number of papers where you were first or last author, minus the number of papers where you were a middle author. You can use the Python code below (requires installing scholarly and thefuzz).

from scholarly import scholarly
from thefuzz import fuzz
 
author_name = NAME_HERE
 
search_query = scholarly.search_author(author_name)
result = next(search_query)
author = scholarly.fill(result)
 
good = 0
bad = 0
 
# Iterate over publications.
for pub in author['publications']:
    publication = scholarly.fill(pub)
    authors_string = publication['bib']['author']
    authors = [name.strip() for name in authors_string.split('and')]
    scores = [fuzz.ratio(author_name, name) for name in authors]
    nauthors = len(authors)
 
    max_value = max(scores)
    max_index = scores.index(max_value)
    if max_index == 0 or max_index == nauthors-1:
        good += 1
    else:
        bad += 1
 
    print(f"Authors: {authors_string}")
    print(f"Good: {good}, Bad: {bad}")
 
lfactor = good - bad
print(f"RESULT: {author_name} L-Factor: {lfactor}")