I have a String and a list as follows.
mystring = "ABC company is good. Also (ALDs) not bad. Sometimes FLJ is bad. I like NYG"
mylist = ['ALD', 'ALDs', 'NMN', 'YEW', 'ABC', 'NYGs']
Now I want to append '_ABB' for every word that appears in the list. For example in the above case I should get an output as follows.
mystring = "ABC_ABB company is good Also ALDs_ABB not bad Sometimes FLJ is bad I like NYG"
I am currently doing it as follows.
splits = mystring.split()
newstring = 
for item in splits:
if item in mylist:
item = item+'_ABB'
for ele in newstring:
# ' '.join(ele) to get the final completed string
I want to know if it is possible to do this in one line using python?
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered