-3
我有一个字符串,名称用单词“and”分隔,并以“First Last”或“Last,First”两种形式输入。我想要生成一个只有姓氏按字母顺序排列的列表。 我是新来的Python,所以我在想,如果有做我所做的事,更短的或更好的方式:从python中的名称中提取姓氏
names = 'John Foo and Baz, Mike Tom and Bar Foo, S. P.'
authors = [ i.strip() for i in names.split("and") ]
comma = [ i.split(',')[0] for i in [i for i in authors if "," in i] ]
nocomma = [ i.split()[-1] for i in [i for i in authors if not "," in i] ]
surnames = comma + nocomma
surnames.sort()
print surnames
使用codereview.stackexchange.com –
你想做什么!?什么是数据的一般形式!! ??请澄清。 – IcyFlame