Jun-22-2018, 01:46 PM
(Jun-22-2018, 01:12 PM)Mr_Keystrokes Wrote: Hmm, this doesn't take into account the instances where the 2 elements being compared are the same.
let's take the check in a function
import csv def check_line(line, isolate): my_set = set(line) return len(my_set & isolate) == len(my_set) with open('isolate_file.txt') as f: new_isolate = {line.strip() for line in f} with open('snapper_data.csv') as sd: rdr = csv.reader(sd) my_isolates = [line[1:] for line in rdr if check_line(line[1:-1], new_isolate)] print(my_isolates)you can do it also like this
import csv with open('isolate_file.txt') as f: new_isolate = {line.strip() for line in f} with open('snapper_data.csv') as sd: rdr = csv.reader(sd) my_isolates = [line[1:] for line in rdr if line[1] in new_isolate and line[2] in new_isolate] print(my_isolates)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs