How To Identify 3 Layer Combinations From Different Lists
I have two different lists (list1 and list2) of image datasets. I want to determine possible three feature combinations considering the integration of both lists, but not individua
Solution 1:
After gathering all the information required, my proposed solution is to use a product
instead:
from itertools import product
def apply_op(list1, list2):
part_1 = product(list1, list1, list2)
part_2 = product(list1, list2, list2)
return set(list(part_1)).union(set(list(part_2)))
print(apply_op(A, B))
EDIT: above solution doesn't work, since the result contains duplicate members in tuples.
def apply_op(list1, list2):
ret = []
for i in range(len(list1)):
for j in range(i + 1, len(list1)):
for k in range(len(list2)):
ret.append((list1[i], list1[j], list2[k]))
for i in range(len(list1)):
for j in range(len(list2)):
for k in range(j + 1, len(list2)):
ret.append((list1[i], list2[j], list2[k]))
return ret
print(apply_op(A, B))
Solution 2:
I am not sure what is exactly that you want, but if you want to merge two lists based on inputs in first lists, I suggest you to use dictionary. You can put element in list1 as key and put elements of list2 two in list, a value to that key. you can then use dictionary methods to update those value lists.
Post a Comment for "How To Identify 3 Layer Combinations From Different Lists"