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?
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
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.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.
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