Ps3 problem 2: http://codepad.org/OSOOGkZp Sorry for all the questions, but is there a better way to return the locations of the keys in a tuple than converting a list into a tuple? Can I somehow start with a tuple and add to it as keys are found? Thanks, sean
You can use matchesLoc += (index, ) if matchesLoc is a tuple. Notice the strange extra comma after index.
Awesome! That is exactly what I wanted to do. I didn't include the strange comma when I tried that. Thanks!
Why would you have? It's completely non-intuitive and ridiculous.
Ah, I think I just figured it out. You can't just say (2) is a tuple, because that's already a mathematical expression that evaluates to 2. Just like if I said x = 4*(2+2) It doesn't think that (2+2) is a tuple with a single value of 4. I guess parentheses are a bit overloaded in python. And, I guess, thinking about it, it's really the simplest and most elegant way to differentiate between a 1-valued tuple and a number in parens. You can also put a dangling comma at the end of a list, so at least they're consistent.
the Python docs are an excellent resource especially the tutorial - they should have been installed on your computer. F1 in IDLE or they are also online http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
Join our real-time social learning platform and learn together with your friends!