brewersfan1976

are_similar.py

Apr 28th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def areSimilar(a, b):
  2.     if a == b:
  3.        return True
  4.  
  5.     a_sort = list(a)
  6.     b_sort = list(b)
  7.    
  8.     a_sort.sort()
  9.     b_sort.sort()
  10.    
  11.     if a_sort != b_sort:
  12.        return False
  13.    
  14.     x = 0
  15.     difference = 0
  16.    
  17.     while x < len(a):
  18.           if a[x] != b[x]:
  19.              difference = difference + 1
  20.            
  21.           x = x + 1
  22.        
  23.     if difference == 2:
  24.        return True
  25.     else:
  26.        return False
Advertisement
Add Comment
Please, Sign In to add comment