Might want to look at `itertools.product` here to simplify the nested loops.