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?
try changing "occurancesStart = occurancesStart, ans" to "occurancesStart = occurancesStart + ans"
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
Thanks Nessman! I got it solved now.
Join our real-time social learning platform and learn together with your friends!