Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

['AB']

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

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

>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]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading