Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import timeit
- def string_match(a, b):
- return sum([max(0, len(m)-1) for m in ''.join(map(lambda x: 'y' if x[0] == x[1] else 'n', zip(a, b))).split('n')])
- def test(func):
- assert(func('xxcaazz', 'xxbaaz') == 3)
- assert(func('abc', 'abc') == 2)
- assert(func('abc', 'axc') == 0)
- assert(func('hello', 'he') == 1)
- assert(func('he', 'hello') == 1)
- assert(func('h', 'hello') == 0)
- assert(func('', 'hello') == 0)
- assert(func('aabbccdd', 'abbbxxd') == 1)
- assert(func('aaxxaaxx', 'iaxxai') == 3)
- assert(func('iaxxai', 'aaxxaaxx') == 3)
- def time_test():
- return test(string_match)
- print timeit.timeit(time_test, number=10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement