Consider I have two groups of string elements (unnecessary string - just for the example):
"strA1, strA2, strA3" and "strB1, strB2, strB3".
I'd like to map elements from the first list with elements from the second list into unique pairs by known law that I can find element in the second list by element in the first list and visa versa.
I know three methods to do it.
Method 1.: Create a map
{'strA1':'strB1', 'strA2':'strB2', 'strA3':'strB3'}
In this case I can find an element from the second list just by key. But if I want to find element from the first list I have to iterate through all dictionary keys.
Method 2.: Create two maps:
{'strA1':'strB1', 'strA2':'strB2', 'strA3':'strB3'}
{'strB1':'strA1', 'strB2':'strA2', 'strB3':'strA3'}
In this case I can find an element by key in both lists but I have to keep two maps for that.
Method 3: Create meaningful indexes (manually or with enum) and use a special parameter to select an element from the pair in a tuple:
from enum import Enum
Index = Enum('Index', ['PAIR_A1B1', 'PAIR_A2B2', 'PAIR_A3B3'], start=0) #understandable names
#direction
A2B = 0
B2A = 1
mappingList = [('strA1','strB1'), ('strA2','strB2'), ('strA3','strB3')]
print(mappingList[Index.PAIR_A1B1.value][A2B]) # I get my mapped string here
Are there another methods?