python merge two lists and remove duplicates code example

Example 1: remove duplicates from a list of lists python

k = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4]]
new_k = []
for elem in k:
    if elem not in new_k:
        new_k.append(elem)
k = new_k
print k
# prints [[1, 2], [4], [5, 6, 2], [3]]

Example 2: python merge list no duplicates

# Create the two lists
l1 = [1, 2, 2, 4]
l2 = [2, 5, 5, 5, 6]
# Find elements that are in second but not in first
new = set(l2) - set(l1)
# Create the new list using list concatenation
l = l1 + list(new)