从Python中括号括起来的字符串中删除唯一字符

时间:2018-10-18 19:48:49

标签: python python-3.x

我有以下格式的名称列表:Last(Maiden),First。 如何删除娘家姓,使其显示为Last,First?

local.loc[~local.index.isin([('done','A')]),:]=0
local.loc[:,~local.index.isin([('done','A')])]=0

1 个答案:

答案 0 :(得分:0)

您可以使用正则表达式删除一对括号内的所有内容:

import re

Name_List = ['Smith (Samsonite), Jennifer', 'Johnson (Scott), Ashley',
             'Williams, Jessica']

Name_List = list(map(lambda x: re.sub(r'\s\(.*\)', '', x), Name_List))
print(Name_List)  # prints ['Smith, Jennifer', 'Johnson, Ashley', ...]
相关问题