anonymous
  • anonymous
help with optional reading think python exercise 8.2. How do I slice and insert new dna into a string and splice it back together again? code attached: #http://www.greenteapress.com/thinkpython/thinkpython.pdf #chapter 8 for loops #brandon MOOC group 3 #oct. 20 prefixes = 'JKLMNOPQ' suffix = 'ack' news=[] for letter in prefixes: news.append( letter + suffix) print news for each word in news if [:1] == 'O': #finds Oack in the list #code to mutate Oack to Ouack elif [:1] == "Q": #finds Qack in the list #code to insert u before ack
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Like this ? prefixes = 'JKLMNOPQ' suffix = 'ack' news=[] for letter in prefixes: if letter == 'O' or letter == 'Q': letter += 'u' news.append( letter + suffix) print news
anonymous
  • anonymous
Btw, if you really want to "insert" a char into a String, as strings are immutable, you should probably do like this : word = word[0] + 'u' + word[1:], but then you have to replace the word in the list : for index, word in enumerate(news): if word[0] in ['O', 'Q']: word = word[0] + 'u' + word[1:] news[index] = word print news
anonymous
  • anonymous
Since you've already put it into a list, I would opt to use the list splice method... for i in range(0, len(news)): letter=news[i][:1] if letter=='O'or letter=='Q': news[i]=news[i][:1]+'u'+news[i][1:] As @FabienToune put it, you will need to replace the word after changing it.

Looking for something else?

Not the answer you are looking for? Search for more explanations.