def addrmask(addr, mask):
    """Applies a bitmask to a memory address, for part 2 of the problem.
    If mask[i] == 0, the corresponding address bit is passed through it.
    Otherwise, address bit i is overwritten with 1 (if mask[i] == 1), or is
    allowed to float (if mask[i] == X). Returns the masked memory address,
    in pseudo-binary representation (i.e., 0/1/X like the mask input). Pass
    this to the next function to expand to a list of memory addresses."""
    baddr = f"{bin(addr)[2:]:>036}"
    baddrmask = "".join([d if mask[i] == "0" else mask[i]
                         for i, d in enumerate(baddr)])
    return baddrmask