In [1]:
l1 = ['a', 'b', 'c']
l2 = ['b', 'c', 'd']
l3 = ['c', 'd', 'e']
In [2]:
l1_l2_and = set(l1) & set(l2)
print(l1_l2_and)
In [3]:
print(type(l1_l2_and))
In [4]:
l1_l2_and_list = list(l1_l2_and)
print(l1_l2_and_list)
In [5]:
print(type(l1_l2_and_list))
In [6]:
print(len(l1_l2_and))
In [7]:
l1_l2_l3_and = set(l1) & set(l2) & set(l3)
print(l1_l2_l3_and)
In [8]:
l1_l2_sym_diff = set(l1) ^ set(l2)
print(l1_l2_sym_diff)
In [9]:
print(list(l1_l2_sym_diff))
In [10]:
print(len(l1_l2_sym_diff))
In [11]:
l1_l2_l3_sym_diff = set(l1) ^ set(l2) ^ set(l3)
print(l1_l2_l3_sym_diff)
In [12]:
l_all = l1 + l2 + l3
print(l_all)
In [13]:
print(set(l_all))
In [14]:
l_all_only = [x for x in set(l_all) if l_all.count(x) == 1]
print(l_all_only)
In [15]:
l1_duplicate = ['a', 'a', 'b', 'c']
In [16]:
l_duplicate_all = l1_duplicate + l2 + l3
l_duplicate_all_only = [x for x in set(l_duplicate_all) if l_duplicate_all.count(x) == 1]
print(l_duplicate_all_only)
In [17]:
l_unique_all = list(set(l1_duplicate)) + list(set(l2)) + list(set(l3))
print(l_unique_all)
In [18]:
l_uniaues_all_only = [x for x in set(l_unique_all) if l_unique_all.count(x) == 1]
print(l_uniaues_all_only)
In [19]:
l1_l2_or = set(l1 + l2)
print(l1_l2_or)
In [20]:
print(list(l1_l2_or))
In [21]:
print(len(l1_l2_or))
In [22]:
l1_l2_l3_or = set(l1 + l2 + l3)
print(l1_l2_l3_or)