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

here is my solution for problem no. 4 in problem set 3.. please check and suggest possible improvements thanks :) http://dpaste.com/hold/565732/

OpenStudy (anonymous):

my opinion/taste: for lines 23 - 28: i would not have repeatedly called subSME (especially inside two loops) - i would have assigned the returned tuple to a variable and used it. I would have used the 'in' operation instead of testing for equality ( http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange) when i wrote that portion I turned the tuple into a list then used the remove method to get rid of the 'exact' matches, then turned it back into a tuple example: http://dpaste.com/565994/

OpenStudy (anonymous):

also ... you increment i1 and i2 on lines 27 and 28 inside their for loops - don't the for loops do that for you? wouldn't lines 27 and 28 cause it to skip items? ( i didn't test it)

OpenStudy (anonymous):

ah thanks for the suggestion..actually i looked for a removing function for tuples couldn't find it so i did it this way..now on i will use the remove function for list.. and the for loop thing..i was a bit confused about that..i thought it only tests for the condition..and for testing it skips or not...i wrote this i=0 for i in range(0,10): print i i=i+1 and it returned 0 to 9..so i think it should be fine???

OpenStudy (anonymous):

ah i think the in method is better than the list :D.

OpenStudy (anonymous):

interesting ... lines 27 and 28 aren't doing anything - range returns a list and the for loop is 'extracting' elements from that list - since you don't do anything with i1 or i2 after you increment them, those two lines don't do anything... i shoulda seen that earlier. try this for i in range(0,20,3): print i i += 1

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
Breathless: Spooky witch but cute
4 hours ago 3 Replies 0 Medals
Arriyanalol: help
3 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 3 Medals
Jaded012023: Please tell me what you all think of this song
6 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
6 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 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!