Created
May 28, 2021 21:49
-
-
Save franps/48e598d88fcc88238f38c7c5cae9d2be to your computer and use it in GitHub Desktop.
panchograma : anagram function developed by pancho
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# panchograma : anagram function developed by pancho | |
def panchograma (p1,p2): # Time complexity is O(2N) | |
letras = {} | |
p1 = p1.lower().replace(' ','') | |
p2 = p2.lower().replace(' ','') | |
for i in p1: # O(N) | |
letras[i] = letras.get(i,0)+1 | |
for i in p2: # O(N) | |
if i in letras and letras[i] > 0: | |
letras[i] = letras [i] - 1 | |
if letras[i] == 0 : | |
letras.pop(i) | |
else: | |
return False | |
return(len(letras) == 0) | |
print(panchograma('samYmasitas','masItassamy')) | |
print(panchograma('Banana não tem caroço','Ornamento canaça boã')) # Estos son palabras de verdad? ni idea, no se portugues | |
print(panchograma("William Shakespeare","I am a weakish speller")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment