Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-317

Even Parity Codeword

Problem

Append an even parity bit to a list of bits. The parity bit is 1 when the number of ones is odd, so the total number of ones in the returned list is always even. Return the new list with the parity bit at the end.

Hint

Count the ones and append 1 when that count is odd.

Test cases

case 1
in: [[1,0,1]]
expected: [1,0,1,0]
case 2
in: [[1,1,0]]
expected: [1,1,0,0]
case 3
in: [[]]
expected: [0]
case 4
in: [[1]]
expected: [1,1]
case 5
in: [[0,0,0,0]]
expected: [0,0,0,0,0]
Starter codePython
def even_parity_codeword(bits):
    # Your code here
    pass

5 test cases · run your code against them in the editor