# compressed list import itertools names = [ ' Tim ', ' Joe ', ' Bill ', ' Susan ', ' Jen ' ] show = [ 1, 0, 1, 0, 1 ] compressed_list = itertools.compress(names, show) print(list(compressed_list)) # [ ' Tim ', ' Bill ', ' Jen ' ]