Skip to content

Instantly share code, notes, and snippets.

@franps
Created May 28, 2021 21:49
Show Gist options
  • Save franps/48e598d88fcc88238f38c7c5cae9d2be to your computer and use it in GitHub Desktop.
Save franps/48e598d88fcc88238f38c7c5cae9d2be to your computer and use it in GitHub Desktop.
panchograma : anagram function developed by pancho
# 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