Ejemplo 1: anagramas de Python
# function to check if two strings are
# anagram or not
def check(s1, s2):
# the sorted strings are checked
if(sorted(s1)== sorted(s2)):
print("The strings are anagrams.")
else:
print("The strings aren't anagrams.")
# driver code
s1 ="listen"
s2 ="silent"
check(s1, s2)
Ejemplo 2: comprobar si anagrama
function isAnagram(stringA, stringB) {
// Sanitizing
stringA = stringA.toLowerCase().replace(/[W_]+/g, "");
stringB = stringB.toLowerCase().replace(/[W_]+/g, "");
// sorting
const stringASorted = stringA.split("").sort().join("");
const stringBSorted = stringB.split("").sort().join("");
return stringASorted === stringBSorted;
}
Ejemplo 3: compruebe si dos cadenas son anagramas python
if sorted(s1) == sorted(s2):
print("The strings are anagrams.")
else:
print("The strings aren't anagrams.")
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)