First of all let's fix a bug in your code. You will be surprised to learn that
you have two alternatives
if (chromosome[i] is not ('A' or 'C' or 'G' or 'T')):doesn't do what you expect. see for yourself:
chromosomes = 'NACGT' for chromosome in chromosomes: print(chromosome, chromosome is not ('A' or 'C' or 'G' or 'T'))
Output:N True
A False
C True
G True
T True
so you replace everything that is not Ayou have two alternatives
if chromosome == 'N': # replace just Nor
if chromosome not in 'ACGT': # replace everything that is not A, C, G or Tor
if chromosome not in ['A', 'C', 'G', 'T']: # replace everything that is not A, C, G or Tsomething like this
import random chromosomes = ['N', 'A', 'C', 'G', 'N', 'T'] new_chromosomes = [random.choice('ACGT') if c == 'N' else c for c in chromosomes] print(new_chromosomes)
Output:['A', 'A', 'C', 'G', 'C', 'T']
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs