There is a similar question, posted in other thread, but I would like to have a different output How to compare two lists to keep matching substrings?
And List A doesn't have a consistent pattern
A = ['dataFile1999', 'dataFile::2000', 'Resultx2001', 'Filter2002']
B = ['2000', '1999', '1998', '2005', '2002','2005']
C = [x for x in A if any(b in x for b in B)]
print(C)
Output:
['dataFile::2000', 'dataFile1999','Filter2002']
But I would like to have the output in the same order as the substring list B also, if there is any string missing - it should still keep the string in the list.
['dataFile::2000','dataFile1999','1998','2005','Filter2002','2005']