I have two lists in Python that look like this:
lst = [1, '?2']
replace_lst1 = ['a','b','c']
For each occurrence of '?2' in lst, I would like to replace it with each element from replace_lst1 thereby producing a list of lists as follows:
res = [ [1,'a'],
[1,'b'],
[1,'c'] ]
Similarly, if I have the following lists:
lst = [1, '?2','?3']
replace_lst1 = ['a','b','c']
replace_lst2 = ['A', 'B', 'C']
I would like to replace '?2' with each element from replace_lst1 and '?3' with each element from replace_lst2, thereby exploring all possible permutations. The result should look like this:
res = [ [1,'a','A'],
[1,'a','B'],
[1,'a','C'],
[1,'b','A'],
[1,'b','B'],
[1,'b','C'],
[1,'c','A'],
[1,'c','B'],
[1,'c','C'] ]
It would be great if you could provide me with some suggestions how to proceed.
Thanks!
replace_lst3??Nformat mandatory? shall it begin at1? it's definitively possible to do what you want, but it looks pretty weird and won't be elegant...replace_lst3. The?Xformat is given. It doesn't begin at 1, actually, the lists are strings. I simplified the things for illustrative purposes. As for the data structure, I'd like the result to be a list of lists since I'll have to do some operations on the result and with this data structure, I know how to proceed.