I am trying to remove the characters from the list generated from the second string. At the end, if the array is empty, it is the permutation of two strings, else it is not.
Is this logic fine?
def is_permutation(string1, string2):
if len(string1) != len(string2):
return False
string2 = list(string2)
for char in string1:
if char in string2:
string2.remove(char)
if not string2:
return True
return False
if __name__ == '__main__':
print(is_permutation("abc", "cba"))
print(is_permutation("bc", "ab"))
print(is_permutation("dog", "god"))