change member of a list that contains only string member

I have a original list with name ‘m’ as below :

m = ['A', 'B', 'C', 'D', 'E']

now, decision maker tells me a list that contains a new group. for example, it says that:


it means that, in my original list, ‘A’ , ‘B’ has been merged together. and my new original list member will be

['AB','C', 'D', 'E']

how can I code this problem in python ?
please halp me to solve it. thanks a lot.

>Solution :

If you are given the string ‘AB’ and then want to manipulate the list, you could try the following.

given = 'AB'
m = [i for i in m if i not in given] + [given]

Leave a Reply