So I have parsed a list from an HTML email, called br_list
:
br_list: [<b>Sent:</b>, <b>To:</b>, <b>Subject:</b>, 'NEFS VII & VIII Manager', 'E-mail: ', 'Office:(508)984-0900 ', 'Cell:(508)965-0064']
And I have a list of sectors, sectors
:
sectors = (
'Fixed Gear Sector',
'Maine Coast Community Sector',
'Maine Permit Bank',
'NCCS',
'NEFS 2',
'NEFS 3',
'NEFS 4',
'NEFS 5',
'NEFS 6',
'NEFS 7',
'NEFS VII',
'NEFS 8',
'NEFS VIII',
'NEFS 9',
'NEFS 10',
'NEFS X',
'NEFS 11',
'NEFS 12',
'NEFS 13',
'New Hampshire Permit Bank',
'Port Clyde Community Groundfish Sector',
'Sustainable Harvest Sector 1',
'Sustainable Harvest Sector 2',
'Sustainable Harvest Sector 3',
'Tri-State Sector',
)
And I would like to see if br_list
contains any entries from sectors
in it. It should be as easy as
if any(i in br_list for i in sectors):
print("yup")
....but nothing gets printed. I assume it fails because it's looking for a single list entry that is a sector, which doesn't exist, even though a sector clearly does exist within one of the list entries.
So:
1) Is there a way to check if any of those sectors exists anywhere in br_list
?
2) If a sector
does exist in br_list
, is there a way to capture just that sector string? In this case, "NEFS VII"
?
** EDIT: ** As was pointed out, my code failed because NEFS VII
is a substring of a list entry, not a list entry itself. I solved it with the accepted answer below.