So I have a list of strings, all with the same length, like this:
list_strings=["A-C-TG--","ATCGTAGC","ATGCGATC","ATGCGGTC"]
What I'm trying to do is, for each position where the first member of list_strings has a "-", remove every character in those same positions from every member of list_strings.
My output would be something like this:
new_list_strings=["ACTG","ACTA","AGGA","AGGG"]
I've tried doing this:
- Creating an empty new list.
- Getting the positions where the first member of
list_stringshas a "-". - Remove the gap from all the strings and append the new string to "new_list_strings"
list_strings=["A-C-TG--","ATCGTAGC","ATGCGATC","ATGCGGTC"]
new_list_strings=[]
positions=[i for i, letter in enumerate(list_strings[0]) if letter == "-"]
for string in list_strings:
for i in range(len(string)):
for pos in positions:
if i==pos:
string2=string[:i]+string[i+1:]
new_list_strings.append(string2)
Unfortunately, this is only removing on one of the positions and not all of them. Anyone knows what I'm doing wrong?