Given a binary file game.dat, containing records of following list format: [game_name, participants]

Write a function in Python that would read contents from the file game.dat and creates a file named basket.dat copying only those records from game.dat where the game name is "Basket Ball"

Source Code

def countRec(country):
    infile = open("game.dat","rb")
    outfile = open("basket.dat","wb")

    try:
        while True:
            record = pickle.load(infile)
            if record[0] == "Basket Ball":
                pickle.dump(record, outfile)
    except EOFError:
        pass
    infile.close()
    outfile.close()