Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sorted string dict approach

from collections import defaultdict


class PermutationsAlt(object):

    def is_permutation(self, str1, str2):
        if str1 is None or str2 is None:
            return False
        if len(str1) != len(str2):
            return False
        unique_counts1 = defaultdict(int)
        unique_counts2 = defaultdict(int)
        for char in str1:
            unique_counts1[char] += 1
        for char in str2:
            unique_counts2[char] += 1
        return unique_counts1 == unique_counts2
Comment

sorted string dict approach

from collections import defaultdict


class PermutationsAlt(object):

    def is_permutation(self, str1, str2):
        if str1 is None or str2 is None:
            return False
        if len(str1) != len(str2):
            return False
        unique_counts1 = defaultdict(int)
        unique_counts2 = defaultdict(int)
        for char in str1:
            unique_counts1[char] += 1
        for char in str2:
            unique_counts2[char] += 1
        return unique_counts1 == unique_counts2
Comment

PREVIOUS NEXT
Code Example
Python :: merge sort dictionary python 
Python :: stop level of the broker 
Python :: Using **kwargs to pass the variable keyword arguments to the function 
Python :: keyword argument python 
Python :: unique lits on python 
Python :: python replace every space, dash and parentheses into underscore 
Python :: plt hist random normal distribution 
Python :: frozenset numbers in python 
Python :: uncompress zip file in pythonanywhere 
Python :: How to use glob.escape() function in python 
Python :: cmd python script stay open 
Python :: apply WEKA filter on customer dataset 
Python :: Python NumPy atleast_1d Function Example when inputs are in high dimension 
Python :: python antigravity 
Python :: use count() function to find if a row is there in sqlite database or not. 
Python :: Python NumPy ascontiguousarray Function Example Tuple to an array 
Python :: Python NumPy array_split Function Example 02 
Python :: Python NumPy dsplit Function Syntax 
Python :: How to obtain a jpeg resolution in python 
Python :: python cos not the same as calculator 
Python :: godot knockback 
Python :: All possible combinations of multiple columns 
Python :: python override inherited method class model constructor 
Python :: penggunaan values di python 
Python :: list python !g 
Python :: python get dataframe vlaues where cell is higher than 
Python :: browser environment: 
Python :: find sum of all elements in a matrix by python 
Python :: Not getting values from Select Fields with jQuery 
Python :: KeyError: 0 python 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =