I have multiple strings that looks like this:
“BPBA-SG790-NGTP-W-AU-BUN-3Y”
I want to compare the string to my list and if part of the string is in the list, I want to get only the part that is found on the list as a new variable.
This is my code:
mylist = ["770", "790", "1470", "1490"]
sq = “BPBA-SG790-NGTP-W-AU-BUN-3Y”
matching = [s for s in mylist if any(xs in s for xs in sq)]
print(matching)
>>> ['770', '790', '1470', '1490']
For example this is what I want to get:
mylist = ["770", "790", "1470", "1490"]
sq = “BPBA-SG790-NGTP-W-AU-BUN-3Y”
matching = [s for s in mylist if any(xs in s for xs in sq)]
print(matching)
>>> 790
Any idea how to do this?