I edited your code and it is giving correct output now:
seq="----AB--C-D-----"newseq="--A--BC---D-"seq=list(seq) #changing maaster sequence from string to listnewseq=list(newseq) #changing new sequence from string to listn=len(seq) #obtaining length of master sequencenewseq.extend('.') #adding a tag to end of new sequence to account for terminal gapsprint(seq, newseq,n) #verification of sequences in list form and lengthfor i in range(len(seq)): if seq[i]!=newseq[i]: if seq[i]=='-': newseq.insert(i,'-') elif newseq[i]=='-': newseq.insert(i,seq[i]) else: newseq.insert(i,seq[i])else: newseq=newseq[0:len(seq)]old=''.join(seq) #changing list to stringnew=''.join(newseq) #changing list to stringnew=new.strip('.') #removing tagprint(old) #verification of master-sequence fidelityprint(new) #verification of matching sequence
output:
----AB--C-D---------AB--C-D-----
and for AA---A--A-----A-----
:
---A-A--AA---A-----A-A--AA---A--