Im creating random combinations using 3 different formats - 300,400 and 500 and I need to remove duplicated combinations. I wonder if there is a good way to compare each tree branch from each data tree and remove duplicated combinations. Thank you in advance!
a = ["abc", "def", "ijk", "lmn", "opq", "rst", "xyz"]
b = ["ijk", "lmn", "opq", "rst", "123", "456" ]
for i in b[:]:
if i in a:
b.remove(i)
>>> b
['123', '456']
another way is to comparing strings , combine your data in a row for example first item of list could be converted to this string:“300400500300400” and so on.
now you can get free from branches and then compare to next list.
hope this help.
Thank you for your feedback. I have been trying to get it to work and I end up with this.
I’m still very beginner in Python, so I’m a bit unsure if it is working properly. Looking at the code it seems to be but I’m not sure if the result is correct.
My first thoughts are at the correct output should be a list of branches common in both lists, but I’m getting none.