I'm a bit stumped with what logic to use to be able to match a list to a CSV-file/list containing values. I've had an idea to use a for loop to simple iterate through the CSV and match it:
for j in range(len(data)):
if STR_list[j] in data[j]:
print(data[j])
But this doesn't actually print out matches as I want it. Here is what the the data and STR_list values look like when printed (before the for loop above):
print(STR_list):
['AGATC', '4', 'AATG', '1', 'TATC', '5']
print(data)
[OrderedDict([('name', 'Alice'), ('AGATC', '2'), ('AATG', '8'), ('TATC', '3')]), OrderedDict([('name', 'Bob'), ('AGATC', '4'), ('AATG', '1'), ('TATC', '5')]), OrderedDict([('name', 'Charlie'), ('AGATC', '3'), ('AATG', '2'), ('TATC', '5')])]
So in this case, the row with 'Bob' would have been a match as the values line up. Should I be using regex for this or am I right in thinking a for loop could be used?
Edit: Here is how I open the CSV (so it seems like it's a list after all?)
with open('file.csv') as csvfile:
reader = csv.DictReader(csvfile)
data = list(reader)