Sep-20-2019, 11:17 AM
If you look at this code you probably notice that in order to explain the solution I created unnecessary list of chunks. We actually don't need to create this, we need the names of amino acids. So we can do lookup right away and we will have oneliner:
Regarding finding solutions to coding problems: clear your mind, separate what from how and work out what technique suits you best.
One way to approach this problem:
"I have a string and i need to get amino acids names from that. I know that I need three letter chunks from that string. Ok, let's suppose that I already have these chunks, what would I do? I lookup somewhere what amino acid corresponds to chunk. Bingo! I know that in order to do lookup one needs dictionary. Let's build one where we can lookup amino acids by chunks. Now let's solve problems of chunking string and lookup...."
[amino_acids[dna[y-x:y]] for y in range(x, len(dna)+x, x) if len(dna[y-x:y]) == 3]Not that it's pretty and easy to read but we don't create unnecessary list and save some memory.
Regarding finding solutions to coding problems: clear your mind, separate what from how and work out what technique suits you best.
One way to approach this problem:
"I have a string and i need to get amino acids names from that. I know that I need three letter chunks from that string. Ok, let's suppose that I already have these chunks, what would I do? I lookup somewhere what amino acid corresponds to chunk. Bingo! I know that in order to do lookup one needs dictionary. Let's build one where we can lookup amino acids by chunks. Now let's solve problems of chunking string and lookup...."
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.