Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

paynito Group Title

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

  • one year ago
  • one year ago

  • This Question is Closed
  1. FabienToune Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    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

    • one year ago
  2. FabienToune Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    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

    • one year ago
  3. Shadowys Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.