def mutate(self, p_mutate):
new_dna = []<EOL>for bit in self.dna:<EOL><INDENT>if random.random() < p_mutate:<EOL><INDENT>bit = '<STR_LIT:1>' if bit == '<STR_LIT:0>' else '<STR_LIT:0>'<EOL><DEDENT>new_dna.append(bit)<EOL><DEDENT>self.dna = '<STR_LIT>'.join(new_dna)<EOL>
Check each element for mutation, swapping "0" for "1" and vice-versa.