Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. def longest_common_domain(email1, email2):
  2.     a = email1.split('@')[1]
  3.     b = email2.split('@')[1]
  4.     # Compare strings at the C speed
  5.     if a == b:
  6.         return a
  7.     min_len = min(len(a), len(b))
  8.     i = -1
  9.     while -i <= min_len and a[i] == b[i]:
  10.         i -= 1
  11.     return a[i:][1:]
  12.  
  13.  
  14. test1 = 'user01@dev.connex.io', 'admin@connex.io'
  15. test2 = 'testtest@gmail.com', 'foobar@mail.ru'
  16. test3 = 'testtest@gmail.com', 'foobar@gmail.com'
  17. test4 = 'testtest@4mail.com', 'foobar@5mail.com'
  18.  
  19. result = longest_common_domain(*test1)
  20. print 'result:', result
  21. assert result == 'connex.io'
  22.  
  23. result = longest_common_domain(*test2)
  24. print 'result:', result
  25. assert result == ''
  26.  
  27. result = longest_common_domain(*test3)
  28. print 'result:', result
  29. assert result == 'gmail.com'
  30.  
  31. result = longest_common_domain(*test4)
  32. print 'result:', result
  33. assert result == 'mail.com'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement