Created
February 13, 2019 15:08
-
-
Save jinyu121/31ea436f0eea9f95185baccafa09bea8 to your computer and use it in GitHub Desktop.
将bib里面的姓名格式化为简写
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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