fork download
  1. a = 'aaabb'
  2. b = 'bbaaa'
  3.  
  4. def isPerm(firstString, secondString):
  5. # if strings are not equal length, they cannot be permutations
  6. # after sorting alphabetically, if the arrays (sorted returns an array)
  7. # are equal they would be a correct permutation.
  8. return len(firstString) == len(secondString) and sorted(firstString) == sorted(secondString)
  9.  
  10. print(isPerm(a, b))
Success #stdin #stdout 0.01s 47720KB
stdin
Standard input is empty
stdout
True