我有三个给定格式的列表:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
如果短语在列表 B 中匹配,则目的是将列表 A 中的短语替换为列表 C 中的相应缩写。请让我知道如何在Python中执行此操作。因此,最终列表 A 将变为:
A = ['**New fund offering** documents required for opening an account in the name of a single Individual', 'Can an Individual open more than one Investment Account or folio']
B = [u'**New fund offering**', u'NFOs', u'Systematic investment plan', u'Systematic investment plans', u'SIPs', u'SWPs']
C = [u'**NFO',** u'NFO', u'SIP', u'SIP', u'SIP', u'SWP']
答案 0 :(得分:0)
您可以使用str.replace
替换部分字符串,并且可以使用in
来检查匹配项:
for idx_a, substring in enumerate(A):
for part, replacement in zip(B, C):
if part in substring:
A[idx_a] = A[idx_a].replace(part, replacement)