<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mutate(self, p_mutate):
 """ Check each element for mutation, swapping "0" for "1" and vice-versa. """

        new_dna = []
        
        for bit in self.dna:
            if random.random() < p_mutate:
                bit = '1' if bit == '0' else '0'
                
            new_dna.append(bit)
            
        self.dna = ''.join(new_dna)