Q:

Python Comparing two lists with different lengths

Hi I would like to compare two list that are different lengths and print a sorted table with items that are missing in each table. I am partially able to accomplish this and print the values that are missing in list_2.  But I am unable to also print the values that are missing in list_1 from list_2, the letter 'z'. How can I perform this to get the desired output below?
list_1 = ['a', 'b', 'c', 'd', 'e', 'f']
list_2 = ['b', 'c', 'f', 'z']

table_format = '{:<10} {:<10}'
print(table_format.format('list_1', 'list_2'))
print('-' * 20)
for x in list_1:
    for y in list_2:
        if x in y:
            print(table_format.format(x, y))
            break
    else:
        print(table_format.format(x,'Missing'))

Current Output:
list_1     list_2    
--------------------
a          Missing   
b          b         
c          c         
d          Missing   
e          Missing   
f          f        

Desired Output:
list_1     list_2    
--------------------
a          Missing   
b          b         
c          c         
d          Missing   
e          Missing   
f          f    
Missing    z

A:

One solution could be using a third list that contains all the elements of the two original lists. Then we could sort the new list and while iterating over it, we could check the existence of elements of the third list in the original ones. Actually making the third list a set would be better. Following the suggestion from Patrick Haugh, we should convert the original lists into sets too before the iteration. Thus the process will be more efficient. Why? Follow this post. Which is faster and why? Set or List?
list_1 = set(['a', 'b', 'c', 'd', 'e', 'f'])  # Or list_1 = {'a', 'b', 'c', 'd', 'e', 'f'}
list_2 = set(['b', 'c', 'f', 'z'])  # list_2 = {'b', 'c', 'f', 'z'}

list_3 = set(list_1 | list_2)
table_format = '{:<10} {:<10}'
print(table_format.format('list_1', 'list_2'))
print('-' * 20)
for elem in sorted(list_3):
    if elem in list_1:
        if elem in list_2:
            print(table_format.format(elem, elem))
        else:
            print(table_format.format(elem, 'Missing'))
    else:
        print(table_format.format('Missing', elem))

Output:
list_1     list_2    
--------------------
a          Missing   
b          b         
c          c         
d          Missing   
e          Missing   
f          f         
Missing    z

