Advanced Python for Data Science Assignment 5

  1. Using the you wrote for Assignment 3, examine the code in light of your understanding of the itertools module. Can you simplify the way you’re doing anything using itertools methods? Are there any opportunities for improving the performance of you code further using itertools?

    Place the modified code in a file called and commit it to the same repository.

  2. Write a program that takes two arguments n and k and prints all binary strings of length n that contain k zero bits, one per line. The program:

    • Must be called
    • Must use the itertools module
    • Must provide a function called zbits(n, k) that returns a set of strings
    • Must contain adequate comments and documentation

    Run the following tests to ensure that the program is correct.

    import binary
    assert binary.zbits(4, 3) == {'0100', '0001', '0010', '1000'}
    assert binary.zbits(4, 1) == {'0111', '1011', '1101', '1110'}
    assert binary.zbits(5, 4) == {'00001', '00100', '01000', '10000', '00010'}

    Commit the program to the repository you used for Assignment 3.