I am new to Python and am trying to figure out how to address the following issue. I have two lists, list1 looks like this:
['10','12','12','23]
And list2 looks like this:
['15','16','13','15']
I also have a dictionary consisting of the following key-values:
dictionary = {
'10': 'AATGCGTAAGCTAGCGATAGATGCAACGTT',
'12': 'GGTCAGAGTTTATCGGTATGTTAGCATGGA',
'23': 'ATGGGCGCGTATATTAAAGGCGCCGCCCTG'
}
The keys in this dictionary consist of those elements in list1. Each element in list1 is also associated with a single element in list2 (in order, such that '10' in list1 is associated with '15' in list2, '12' in list1 with '16' in list2, etc.).
For each element in list1, I would like to take the associated dictionary value, and insert characters into specific positions using the associated element in list2 to determine the positions. So far I've been working on a for loop to do this:
for i in list1:
dict_key = dictionary.get(i)
pos = int(list2[0])
full = dict_key[:pos] + '[' + dict_key[pos] + ']' + dict_key[(pos+1):]
print(full)
I would like my final output to look like this:
AATGCGTAAGCTAGC[G]ATAGATGCAACGTT
GGTCAGAGTTTATCGG[T]ATGTTAGCATGGA
GGTCAGAGTTTAT[C]GGTATGTTAGCATGGA
ATGGGCGCGTATATT[A]AAGGCGCCGCCCTG
But my output currently looks like this because I am specifically calling for only index 0 from list2:
AATGCGTAAGCTAGC[G]ATAGATGCAACGTT
GGTCAGAGTTTATCG[G]TATGTTAGCATGGA
GGTCAGAGTTTATCG[G]TATGTTAGCATGGA
ATGGGCGCGTATATT[A]AAGGCGCCGCCCTG
I want to increase the element that's called for in list2 by 1 with each iteration of the loop, but I can't seem to figure it out. Should I define a new variable using range? Any comments will be appreciated!