here is my solution for problem no. 4 in problem set 3.. please check and suggest possible improvements thanks :) http://dpaste.com/hold/565732/
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/
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)
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???
ah i think the in method is better than the list :D.
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
Join our real-time social learning platform and learn together with your friends!