Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

anagram program in python

def IsAnagram(string1,string2):
    lenth = len(string2)
    total = 0 
    for char in string1:
        if char in string2:
            total += 1
    if total == lenth:
        return True 
    return False
print(IsAnagram("amd","madd"))
Comment

anagram python

def isAnagram(A,B):
  if sorted(A) == sorted(B):
    print("Yes")
  else:
    print("No")
isAnagram("earth","heart") #Output: Yes

#Hope this helps:)
Comment

anagram

var firstWord = "Mary";
var secondWord = "Army";

isAnagram(firstWord, secondWord); // true

function isAnagram(first, second) {
  // For case insensitivity, change both words to lowercase.
  var a = first.toLowerCase();
  var b = second.toLowerCase();

  // Sort the strings, and join the resulting array to a string. Compare the results
  a = a.split("").sort().join("");
  b = b.split("").sort().join("");

  return a === b;
}
Comment

anagram

import java.util.Arrays;  
   
public class AnagramString {  
    static void isAnagram(String str1, String str2) {  
        String s1 = str1.replaceAll("s", "");  
        String s2 = str2.replaceAll("s", "");  
        boolean status = true;  
        if (s1.length() != s2.length()) {  
            status = false;  
        } else {  
            char[] ArrayS1 = s1.toLowerCase().toCharArray();  
            char[] ArrayS2 = s2.toLowerCase().toCharArray();  
            Arrays.sort(ArrayS1);  
            Arrays.sort(ArrayS2);  
            status = Arrays.equals(ArrayS1, ArrayS2);  
        }  
        if (status) {  
            System.out.println(s1 + " and " + s2 + " are anagrams");  
        } else {  
            System.out.println(s1 + " and " + s2 + " are not anagrams");  
        }  
    }  
   
    public static void main(String[] args) {  
        isAnagram("Keep", "Peek");  
        isAnagram("Mother In Law", "Hitler Woman");  
    }  
}
Comment

anagram

def anagram(a, b):
    return True if sorted(a) == sorted(b) else False

# Based on the answer below :D
Comment

anagram

// for 2 strings s1 and s2 to be anagrams
// both conditions should be True
// 1 their length is same or 
len(s1)==len(s2)
// 2 rearranging chars alphabetically make them equal or 
sorted(s1)==sorted(s2)
Comment

Anagram

const anagram = (str1, str2) => {
    return str1.toLowerCase().split('').sort().join('') === str2.toLowerCase().split('').sort().join('');
};

let test = anagram('Regallager', 'Lagerregal');
console.log(test);
Comment

anagram

//find the anagram if two word has the same characters for example word 1: listen, word 2: silent, if the characters are the same return true otherwise return false

//str1="eat"  str2="ate"
//str1="bar " str2="bare"
//str1="bba"  str2="aab"
function areAnagram(str1,str2)
{
    // Get lengths of both strings
    let n1 = str1.length;
    let n2 = str2.length;

    // If length of both strings is not same,
    // then they cannot be anagram
    if (n1 != n2)
        return false;

    // Sort both strings
    let x =str1.split("").sort();
    let y  =str2.split("").sort()
    console.log(x ,y);

    // Compare sorted strings
    for (let i = 0; i < n1; i++){

        if (x[i] != y[i])
            return false;
    }

    return true;
}
let str1="netsil";
let str2="listen";

console.log( areAnagram(str1,str2));
Comment

PREVIOUS NEXT
Code Example
Python :: how to convert datetime to integer in python 
Python :: python bytes 
Python :: ip validity checker python 
Python :: python generate set of random numbers 
Python :: python primes 
Python :: multiple arguments with multiprocessing python 
Python :: find length of string in python 
Python :: ipaddress in python 
Python :: pandas filter rows by value 
Python :: split and only grab first part of string 
Python :: python append list 
Python :: compare times python 
Python :: line plot python only years datetime index 
Python :: django create superuser from script 
Python :: find total no of true in a list in python 
Python :: python how to play mp3 file 
Python :: for pyton 
Python :: mapping with geopandas 
Python :: fastapi oauth2 
Python :: arithmetic in python 
Python :: python opérateur ternaire 
Python :: change the number in 3rd line to get factorial for the number you want. Ex: num = 30 
Python :: seaborrn set figsize 
Python :: Reverse an string Using Stack in Python 
Python :: python regex search a words among list 
Python :: terminal output redirect to a file 
Python :: python countdown from 20 down to 0 
Python :: Group based sort pandas 
Python :: lambda and function in python 
Python :: get all different element of both list python 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =