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

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.

OpenStudy (anonymous):

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

OpenStudy (anonymous):

If you make one change to the following line... if x not in matches: ...you won't need the second for loop.

OpenStudy (anonymous):

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

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
Arriyanalol: i need help
1 day ago 7 Replies 1 Medal
Arriyanalol: CONGRATS to me
2 days ago 8 Replies 2 Medals
Legomaster346: What colleges are good that are near Arab Alabama?
1 week ago 5 Replies 0 Medals
Arriyanalol: i need help
1 week ago 6 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!