I'm on problem 3.4. I've written code that works, but I'm not sure if this is the method that would be recommended for the class. Code to follow as I don't know how to attach a link. I don't remember the lectures covering lists, etc. so I feel I've had to possibly solve it in a way not intended in the original class. The problem is how to remove duplicates from tuples as the code they provide results in a tuple with many duplicates. Actually if I could just remove every item which has a duplicate I wouldn't have to even check it against exact matches.
Here's the code I wrote, def subStringMatchExactlyOneSub(target,key): possible = subStringMatchOneSub(key,target) exact = subStringMatchExact(target,key) matches = [] for x in possible: if x not in matches: matches.append(x) for y in exact: matches.remove(y) newMatches = tuple(matches) return newMatches
If you make one change to the following line... if x not in matches: ...you won't need the second for loop.
lists are covered in the readings. you always need to figure out the best data structure to use in your algorithm - then use it. the problem only required returning a tuple, it didn't require what went on inside the function. so looks ok to me http://pastebin.com/cK60KNp9
Join our real-time social learning platform and learn together with your friends!