Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 9 Online
OpenStudy (anonymous):

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?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

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

OpenStudy (anonymous):

Thanks Nessman! I got it solved now.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!