Question:
I’m getting a bit more used to python now, and my professor has started teaching us about lists and string manipulation, list slicing and all of that. He proposed an exercise which I’m pretty sure can be solved by just using list slices and should not need super specific inbuilt python functions, but I have no clue as in how to start thinking about this problem. It goes as follows:“Create a function, lets call it “generate_n_gaps”, that has as parameters a string ‘dna’ of any length that includes any combination of the characters in the string DNA = ‘ATCG’ (just like the dna sequencing we see in biology) and a gap that we will denote as GAP = ‘_’ , and an integer parameter ‘n’. The function must return a list with all variations of ‘dna’ containing up to n extra gaps without repetition.”
Here are a couple of examples:
This is what my function returns for the first example:
Answer:
this will flatten your list of list. hope it helps.If you have better answer, please add a comment about this, thank you!