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

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

OpenStudy (anonymous):

You can use matchesLoc += (index, ) if matchesLoc is a tuple. Notice the strange extra comma after index.

OpenStudy (anonymous):

Awesome! That is exactly what I wanted to do. I didn't include the strange comma when I tried that. Thanks!

OpenStudy (anonymous):

Why would you have? It's completely non-intuitive and ridiculous.

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

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

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!
Latest Questions
YoungBlood: pfp wonu2019t let me switch
20 minutes ago 1 Reply 0 Medals
Austinsbabygirl4life: Do you think guys would survive on periods?
3 hours ago 22 Replies 2 Medals
alyviahwillis: if anyone has any questions feel free to DM me... I don't mind at all.
5 hours ago 0 Replies 0 Medals
Rosee5656: how do I level up!??!? >,
3 hours ago 14 Replies 4 Medals
Abby13915: I made an alpaca for my fashion club
8 hours ago 3 Replies 0 Medals
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!