I have a sequence like this:
ABCDEFGHIJKL
I would like to insert the strings:
'-(c0)-' after elements 1 and 3
'-(c1)-' after elements 2 and 4
'-(c2)-' after elements 5 and 6
This is the kind of code I was writing:
list_seq = list('ABCDEFGHIJKL')
new_list_seq = list('ABCDEFGHIJKL')
start_end = [(1,3), (2,4), (5,6)]
for index,i in enumerate(start_end):
pair_name = '-(c' + str(index) + ')-'
start_index = int(i[0])
end_index = int(i[1])
new_list_seq.insert(start_index, pair_name)
new_list_seq.insert(end_index, pair_name)
print ''.join(new_list_seq)
The output I would want is:
AB-(c0)-C-(c1)-D-(c0)-E-(c1)-F-(c2)-G-(c2)-HIJKL
(where c0 was inserted after 1 and 3 positions, c1 was inserted after 2 and 4, and c2 was inserted after 5 and 6).
But the output I get is:
A-(c0)--(c1)-B-(c1)--(c2)--(c2)--(c0)-CDEFGHIJKL
I think possibly the problem is that as I incorporate an item into the string, the indices change, so then all subsequent inclusions after the first one are not in the right positions?
Could anyone explain how to do this properly?