I have two lists of protein sequences, I have to check every entry's existence in the two lists, say like list A = [1,2,3,4]list B= [3,4,5]result = [[1, true, false],[2, true, false],[3, true, true],[4, true, true],[5, false, true]]I did it this way. Not sure if it's the right waydef FindDifferences():        df1 = pd.read_csv('Gmax_v6_annotation_info.txt', names=['name'], usecols=[0], delimiter='\t')    df2 = pd.read_csv('Gmax_v9_annotation_info.txt', names=['name'], usecols=[2], delimiter='\t')    v6_set = set(df1['name'])    v9_set = set(df2['name'])    result = []    for val in v6_set:        if val in v9_set:            result.append([val, True, True])        else:            result.append([val, True, False])    for val in v9_set:        if val not in v6_set:            result.append([val, False, True])    result_df = pd.DataFrame(result, columns=['name', 'inv6', 'inv9'])    result_df.to_csv('result_csv.csv', index=False, header=False)    return
Check value existence in two lists and gather the result in a csv
python;pandas;bioinformatics
General problemIt's not much, but for your general problem, mathematically speaking, I'd split the logic into three steps (It might be a bit more code, but personally speaking, it keeps things cleaner):I'd intersect list_A with list_B:def intersect(list_A, list_B):    return [[x, True, True] for x in set(list_A).intersection(list_B)]Which is going to give you:[[3, True, True], [4, True, True]]Then, I'd do list_A - list_B:def a_diff_b(list_A, list_B):    return [[x, True, False] for x in set(list_A).difference(list_B)]Which is going to give you:[[1, True, False], [2, True, False]]Then, I'd do list_B - list_A:def b_diff_a(list_A, list_B):    return [[x, False, True] for x in set(list_B).difference(list_A)]Which is going to give you:[[5, False, True]]IntersectionIn mathematics, the intersection A  B of two sets A and B is the set  that contains all elements of A that also belong to B (or  equivalently, all elements of B that also belong to A), but no other  elements.ComplementIn set theory, the complement of a set A refers to elements not in A.  The relative complement of A with respect to a set B, also termed the  difference of sets A and B, written B  A, is the set of elements in B  but not in A. When all sets under consideration are considered to be  subsets of a given set U, the absolute complement of A is the set of  elements in U but not in A.