Python Function to Zip Two Files into a List of Bytes

  • Share this:

Code introduction


The function takes two files and returns a list containing the corresponding bytes of the two files, compressed in a zip-like manner.


Technology Stack : Built-in libraries

Code Type : File processing

Code Difficulty : Intermediate


                
                    
def zip_file(file1, file2):
    with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
        zipped = zip(f1, f2)
        return list(zipped)