Suppose I have two lists of indices
letters = ['a', 'c']
numbers = ['1','2','6']
These lists are generated based on an interactive web interface element and is a necessary part of this scenario.
What is the most computationally efficient way in python I can use these two lists to search through the third list below for items?
list3 = ['pa1','pa2','pa3','pa4','pa5','pa6',
'pb1','pb2','pb3','pb4','pb5','pb6',
'pc1','pc2','pc3','pc4','pc5','pc6',
'pd1','pd2','pd3','pd4','pd5','pd6']
Using the letters and numbers lists, I want to search through list3 and return this list
sublist = ['pa1', 'pa2, 'pa6', 'pc1', 'pc2', 'pc6']
I could do something like this:
sublist = []
for tag in list3:
for l in letters:
for n in numbers:
if l in tag and n in tag:
sublist.append(tag)
But I'm wondering if there's a better or more recommended way?