A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

Hi, I'm having a problem with utilizing tuples in Pset 3 Question 2. My code is here: http://dpaste.com/530921/ My problem is that this code creates a nested tuple. For example if I use 'a' as the key, and the target as 'atgacatgcacaagtatgcat', it returns: (((((((0, 3), 5), 9), 11), 12), 15), 19). What do I need to do to my code so it stays as a single level tuple?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    try changing "occurancesStart = occurancesStart, ans" to "occurancesStart = occurancesStart + ans"

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Tuples are immutable, meaning you cannot add or subtract elements after creation. One option would be to use a list until your data set is complete, then call tuple on the list.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you can add tuples together and create a single tuple, I've done so in my code. and I've done edited shaneb's code to do so as well, mind you that first post was me speaking before i thought so its wrong I'm not sure whats the etiquette on just completeing someones work for them then posting it first the original variable needs to be a tuple to start so before occurancesStart = ans, you need an occurancesStart = () #an empty tuple second, the correct statement I wanted to post above was occurancesStart = occurancesStart + (ans,) the parens and the comma and important, try it without it and see what i mean. in this instance your not changing a tuple, you are creating a brand new tuple with the contents of the old ones. the change from comma to addition is important as well. I hope this came across clearly, I'm not The best speaker

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks Nessman! I got it solved now.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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.