Reputation: 349
I have three lists - base, match, and replac
; match
and replac
are same length
base = ['abc', 'def', 'hjk']
match = ['abc', 'hjk']
replac = ['abcde', 'hjklm']
I would like to modify the base
list by matching string items in match
and replace these with the same index item from replac
.
Expected output: base = ['abcde', 'def', 'hjklm']
Upvotes: 0
Views: 37
Reputation: 6238
Here is how I'd do it:
mapp = dict(zip(match,replac))
res = [mapp[e] if e in mapp else e for e in base]
Upvotes: 2