human
I am working on the file "Python/data_structures/Arrays-Strings.ipynb".
The first task is:
P2. Check Permutation: Given two strings, write a method to decide if one is the permutation of the other.
Can you write Python program for it?

Give me a the Python program you requested?
assistant
#Here is the Python program you requested.

# Using a hashmap.
# Checking if str1 is a permutation of str2.
# Assumptions: The strings can have repeated characters.
# Time Complexity: O(n)
def if_permute(str1, str2):
    if len(str1) != len(str2):
        return False
    
    def get_chr_dict(string):
        chr_dict = {}
        for char in string:
            if char not in chr_dict:
                chr_dict[char] = 1
            else:
                chr_dict[char] += 1
        return chr_dict
    
    str1_d = get_chr_dict(str1) # String 1.
    str2_d = get_chr_dict(str2) # String 2.
    
    # Compare dictionaries.
    for char in str1_d:
        if char not in str2_d or str2_d[char] != str1_d[char]:
            return False
    
    return True

# Test Cases
print(if_permute("", ""))
print(if_permute("abc", "abc"))
print(if_permute("abbc", "abbc"))
print(if_permute("abcc", "abcc"))
print(if_permute("aaa", "aaa"))
print(if_permute("aaad", "aaac"))