Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def longest_common_domain(email1, email2):
- a = email1.split('@')[1]
- b = email2.split('@')[1]
- # Compare strings at the C speed
- if a == b:
- return a
- min_len = min(len(a), len(b))
- i = -1
- while -i <= min_len and a[i] == b[i]:
- i -= 1
- return a[i:][1:]
- test1 = 'user01@dev.connex.io', 'admin@connex.io'
- test2 = 'testtest@gmail.com', 'foobar@mail.ru'
- test3 = 'testtest@gmail.com', 'foobar@gmail.com'
- test4 = 'testtest@4mail.com', 'foobar@5mail.com'
- result = longest_common_domain(*test1)
- print 'result:', result
- assert result == 'connex.io'
- result = longest_common_domain(*test2)
- print 'result:', result
- assert result == ''
- result = longest_common_domain(*test3)
- print 'result:', result
- assert result == 'gmail.com'
- result = longest_common_domain(*test4)
- print 'result:', result
- assert result == 'mail.com'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement