from PythonLabs.BitLab import Code

def parity(x):
    "Return the parity bit (a 1-bit Code object) for code x"
    p = Code(0,1)       # initialize p to 0
    for bit in x:
        p = p ^ bit     # ^ means "exclusive OR"
    return p
