(Jan-25-2017, 09:40 AM)buran Wrote: given that question is "find how many characters are the same":
count_of_equal_items('skaperen','skapare') -> 4, why not 5 (skap#r##) or 6 (skap#re##)?
count_of_equal_items('war','raw') -> 0, why not 1 (#a#)?
i should have stated it in a different way: what is the length of the longest prefix in common
sorry that i worded it poorly.
an implementation would start with an index of 0 incrementing by 1 at the end of the loop, breaking out of the loop when an unequal comparison happens or the end of either argument is reached, returning the index where it was unequal or ended which is also the length of the common prefix.
(Jan-25-2017, 09:32 AM)wavic Wrote: Python difflib? I never used it and don't know what it providesit looks like it could be the thing:
Output:[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import difflib
>>> sm = difflib.SequenceMatcher()
>>> sm.set_seq1('skaperen')
>>> sm.set_seq2('skapare')
>>> sm.find_longest_match(0,7,0,7).size
4
>>>
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.