Advertisement
Guest User

DoshkoCode

a guest
Apr 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. import timeit
  2.  
  3. def string_match(a, b):
  4.     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')])
  5.  
  6. def test(func):
  7.     assert(func('xxcaazz', 'xxbaaz') == 3)
  8.     assert(func('abc', 'abc') == 2)
  9.     assert(func('abc', 'axc') == 0)
  10.     assert(func('hello', 'he') == 1)
  11.     assert(func('he', 'hello') == 1)
  12.     assert(func('h', 'hello')  == 0)
  13.     assert(func('', 'hello') == 0)
  14.     assert(func('aabbccdd', 'abbbxxd') == 1)
  15.     assert(func('aaxxaaxx', 'iaxxai') == 3)
  16.     assert(func('iaxxai', 'aaxxaaxx') == 3)
  17.  
  18. def time_test():
  19.     return test(string_match)
  20.  
  21. print timeit.timeit(time_test, number=10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement