Skip to content

Instantly share code, notes, and snippets.

@jinyu121
Created February 13, 2019 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinyu121/31ea436f0eea9f95185baccafa09bea8 to your computer and use it in GitHub Desktop.
Save jinyu121/31ea436f0eea9f95185baccafa09bea8 to your computer and use it in GitHub Desktop.
将bib里面的姓名格式化为简写
def process_name(name):
names=[]
for nm in [x.strip() for x in name.split()]:
if '-' in nm:
tmp = [x.strip() for x in nm.split('-')]
tmp = [x[0]+"." for x in tmp]
names.append("-".join(tmp))
else:
names.append(nm[0]+".")
return " ".join(names)
def process_authors(data):
data = [x.strip() for x in data.split(" and")]
data_out=[]
for name in data:
first_name, *last_name = name.split(",")
last_name = [x.strip() for x in last_name]
last_name = [process_name(x) for x in last_name]
data_out.append("{}, {}".format(first_name, ", ".join(last_name)))
return " and ".join(data_out)
while True:
data=input()
print()
print(process_authors(data))
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment