I have a list (or a set or tuple if I choose) of 56 different fish species. I would like to "scan" thru a CSV file to recognize any occurrence of any of the fish species.
I tried:
with open(file_path) as f:
for line in f:
if (stocks in line):
fish, remainder = line.split('\t')
print("fish:", fish)
print("remainder:", remainder)
but that fails because of:
TypeError: 'in <string>' requires string as left operand, not tuple
So I am looking for a way for this to succeed.
The list of possible occurrences:
stocks = (
'GB COD EAST',
'GBE COD',
'GB COD WEST',
'GBW COD',
'GOM COD',
'GB HADDOCK EAST',
'GBE HADD',
'GB HADDOCK WEST',
'GBW HADD',
'GOM HADDOCK',
'GOM HADD',
'GOM HAD',
'GOM HADOCK',
'PLAICE',
'DABS',
'POLLOCK',
'POLL',
'REDFISH',
'REDS',
'RED',
'WHITE HAKE' ,
'WHITEHAKE',
'WHAKE',
'WHAK',
'GB WINTER FLOUNDER',
'GB BB',
'GB WINTER',
'GB BLACK BACKS',
'GB BLACKBACKS',
'GOM WINTER FLOUNDER',
'GOM BLACKBACKS',
'GOM BB',
'GOM WINTER',
'SNE WINTER FLOUNDER',
'SNE WINTER',
'SNE/MA WINTER FLOUNDER',
'SNE BLACKBACK',
'SNE BLACKBACKS',
'SNE BB',
'WITCH FLOUNDER',
'WITCH',
'WHICH',
'WHITCH',
'GREYSOLE',
'GREY SOLE',
'CC/GOM YELLOWTAIL FLOUNDER',
'GOM YELLOWTAIL',
'GOM YELLOW TAIL',
'GOM YT',
'GB YELLOWTAIL FLOUNDER',
'GB YELLOWTAIL',
'GB YT',
'SNE/MA YELLOWTAIL FLOUNDER',
'SNE YT',
'SNE YELLOWTAIL',
'SNE YELLOW TAIL',
'SCALLOP IFQ'
)
stocksis a tuple. You are looking for a tuple object in a string. Instead, you need a separateforloop to go through each string inside the overall tuple.sstocks = set(stocks)