Python:用缩写替换列表中的语句

Python:用缩写替换列表中的语句,python,python-3.x,list,Python,Python 3.x,List,我有三个给定格式的列表: 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 investmen

我有三个给定格式的列表:

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']
目的是将列表A中的短语替换为列表C中相应的缩写,前提是该短语与列表B中的短语匹配。请让我知道如何在Python中执行此操作。因此,最终列表A将变成:

A = ['NFO documents required for opening an account in the name of a single Individual', 'Can an Individual open more than one Investment Account or folio']

您可以使用
str.replace
替换部分字符串,也可以使用
中的
检查匹配项:

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)

您可以向我们展示任何尝试吗?使用
dict(zip(B,C))
创建映射。然后考虑如何做你的替代品。问题可能是贪婪匹配与非贪婪匹配、取决于使用顺序的替换(例如,替换A创建一个字符串,可以用B替换,没有A是不可能的),等等。也就是说,您只需要替换方法。。。当您在Python文档中搜索字符串操作函数时,应该已经找到了。