Home > database >  change member of a list that contains only string member
change member of a list that contains only string member

Time:06-23

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:

['AB']

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. Regards.

CodePudding user response:

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]

CodePudding user response:

another way to do

m = ["A","B","C","D","E"]
n = m[0]   m[1]
o = [n]   m[2:5]
print(o)
  • Related