Good day.
I have the following 2 list that I need to compare for a match. I need to find if listB items are in listA and then return the item in listA.
listA = ['abcd755 - (45)', 'abcd754 - (32.12)', '3xas34a - (43.23)', '01shdsa - (0.01)']
listB = ['abcd754', '23xas34a', 'abcd755', '01shdsa']
out = []
for b in listB:
if any(a.startswith(b) for a in listA):
out.append(b)
print (out)
Current Output:
['abcd754', 'abcd755', '01shdsa']
Intended Output:
['abcd754 - (32.12)', 'abcd755 - (45)' , '01shdsa - (0.01)']