Practicing for my interview, I am working on some problems in Python.
This problem is to decide two strings are permutation (or anagrams) of each each other.
def is_permutation(first, second):
if len(first) != len(second):
return False
first_arr = [0 for i in range(256)] # ASCII size
second_arr = [0 for i in range(256)] # ASCII size
for i in range(len(first)):
first_arr[ord(first[i])] += 1
second_arr[ord(second[i])] += 1
if first_arr != second_arr:
return False
else:
return True
I feel this code can be more efficient, but I cannot make it. Can anybody give me advice or tip so that I can improve please?