0

I'm trying to make a program to do RNA Synthesis for me in biology because it's extremely tedious. I have gotten to the step in the program where I take the string and split it into a list in groups of 3: sssdddfff --> ['sss', 'ddd', 'fff'] This the method that I'm trying works in my head, but it doesn't seem to work if I actually run it. Here's the code:

list = []
  i = 1
  num = 1
  digit = 0

  while num * 3 < len(dna):

    while i < 3:
      i = i + 1
      list.insert(num, dna[digit])
      digit = digit + 1
    num = num + 1

  print (list)

I've shown you what I expect, but whenever I put this string in sssdddfff as a test, I get this instead of what I needed to happen: ['s', 's'] I'm not sure if I just made a dumb mistake or if there's an easier way to do this, but I can't find anything.

Tabulate
  • 611
  • 6
  • 19

1 Answers1

0

You can just iterate through your string and separate it like so:

dna_split = []
for i in range(len(dna)//3):
    dna_split.append(dna[i*3:(i+1)*3])

Also do not use list as a variable name.

Akaisteph7
  • 5,034
  • 2
  • 20
  • 43