An **anagram** is the result of rearranging the letters of a word to produce a new word.

**Note:** anagrams are case insensitive

Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.


## Examples

* `"foefet"` is an anagram of `"toffee"`

* `"Buckethead"` is an anagram of `"DeathCubeK"`

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def is_anagram(test, original):
	

Solutions:
def is_anagram(test, original):
	return sorted(original.lower()) == sorted(test.lower())


from collections import Counter

def is_anagram(test, original):
	return Counter(test.lower()) == Counter(original.lower())


def is_anagram(test, original):
	return sorted(test.upper()) == sorted(original.upper())


def is_anagram(test, original):
	(test_dict, original_dict) = ({}, {})
	for i in test.lower():
		test_dict[i] = test_dict.get(i, 0) + 1
	for i in original.lower():
		original_dict[i] = original_dict.get(i, 0) + 1
	return test_dict == original_dict


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	count = [0] * 26
	for i in range(len(test)):
		count[(ord(test[i]) & 31) - 1] += 1
		count[(ord(original[i]) & 31) - 1] -= 1
	return not any(count)


def is_anagram(test, original):
	a = sorted(test.lower())
	b = sorted(original.lower())
	c = ''.join(a)
	d = ''.join(b)
	if c == d:
		return True
	else:
		return False


def is_anagram(test, original):
	go = len(test) == len(original)
	arr = []
	if go:
		for i in test:
			arr.append(i.lower() in original.lower())
		return False not in arr
	else:
		return False


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	for l in test.lower():
		if l not in original.lower():
			return False
	return True


from operator import eq
from collections import Counter

def is_anagram(test, original):
	return eq(*map(Counter, map(str.lower, (test, original))))


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	return sorted(test.lower()) == sorted(original.lower())


def is_anagram(test, original):
	if sorted(test.lower()) == sorted(original.lower()):
		return True
	else:
		return False


is_anagram = lambda t, o: sorted(t.lower()) == sorted(o.lower())


aprime = {'a': 2, 'c': 5, 'b': 3, 'e': 11, 'd': 7, 'g': 17, 'f': 13, 'i': 23, 'h': 19, 'k': 31, 'j': 29, 'm': 41, 'l': 37, 'o': 47, 'n': 43, 'q': 59, 'p': 53, 's': 67, 'r': 61, 'u': 73, 't': 71, 'w': 83, 'v': 79, 'y': 97, 'x': 89, 'z': 101}

def aprime_sum(str):
	strChList = list(str.lower())
	return sum([aprime[x] for x in strChList])

def is_anagram(test, original):
	if aprime_sum(test) == aprime_sum(original):
		return True
	else:
		return False


def is_anagram(test, original):
	return set(original.lower()) == set(test.lower()) if len(test) == len(original) else False


def is_anagram(test, original):
	a = list(test.lower())
	s = list(original.lower())
	if len(a) != len(s):
		return False
	else:
		for i in a:
			cond = False
			k = 0
			while k != len(s) and cond == False:
				if i == s[k]:
					a.remove(i)
					s.remove(i)
					cond = True
				k += 1
			if cond == False:
				return False
		if len(a) != len(s):
			return False
		else:
			return True


def is_anagram(test, original):
	flag = 0
	if len(test) != len(original):
		return False
	else:
		for i in test.lower():
			if i not in original.lower():
				flag = 1
			else:
				continue
		if flag == 1:
			return False
		else:
			return True


def is_anagram(test, original):

	def to_dict(word):
		dictionary = {}
		for w in word.lower():
			if w not in dictionary:
				dictionary[w] = 0
			else:
				dictionary[w] += 1
		return dictionary
	return to_dict(test) == to_dict(original)


is_anagram = lambda a, b, s=sorted: s(a.lower()) == s(b.lower())


def is_anagram(s, l):
	n = len(s)
	if len(l) != n:
		return False
	s = s.lower()
	l = l.lower()
	h = [0 for x in range(26)]
	for i in range(n):
		h[ord(s[i]) - 97] += 1
		h[ord(l[i]) - 97] -= 1
	return h.count(0) == 26


def is_anagram(test: str, original: str) -> bool:
	return all([all([_ in original.lower() for _ in test.lower()]), len(test) == len(original)])


def is_anagram(test, original):
	test = test.lower()
	original = original.lower()
	testcount = 0
	for i in test:
		if i in original:
			testcount += 1
	originalcount = 0
	for i in original:
		if i in test:
			originalcount += 1
	if testcount == originalcount and testcount == len(test) and (originalcount == len(original)):
		return True
	else:
		return False


def is_anagram(test, original):
	if len(test) == len(original):
		test = test.lower()
		original = original.lower()
		count = 0
		for char in test:
			if char in original:
				count += 1
		if count == len(test):
			return True
		else:
			return False
	else:
		return False


def is_anagram(test, original):
	test_list = []
	original_list = []
	for i in test.lower():
		test_list.append(i)
	for i in original.lower():
		original_list.append(i)
	test_list.sort()
	original_list.sort()
	print(test_list)
	print(original_list)
	if test_list == original_list:
		return True
	else:
		return False


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	letters = {}
	for i in test.lower():
		if i in letters:
			letters[i] += 1
		else:
			letters[i] = 1
	for i in original.lower():
		if i not in letters:
			return False
		if original.lower().count(i) != letters[i]:
			return False
	return True


def is_anagram(t, o):
	return sorted([*t.lower()]) == sorted([*o.lower()])


def is_anagram(test, original):
	x = list(test.lower())
	y = list(original.lower())
	x = sorted(x)
	y = sorted(y)
	if x == y:
		return True
	else:
		return False


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	a = sorted(test.lower())
	b = sorted(original.lower())
	if a == b:
		return True
	else:
		return False


def is_anagram(test, original):
	sorted_test = sorted(list(test.lower()))
	sorted_original = sorted(list(original.lower()))
	return sorted_test == sorted_original


def is_anagram(test, original):
	letters = [c for c in test.lower()]
	for char in original.lower():
		if char in letters:
			del letters[letters.index(char)]
		else:
			return False
	return not bool(len(letters))


import collections

def is_anagram(test, original):
	return collections.Counter([i.lower() for i in sorted(test)]) == collections.Counter([i.lower() for i in sorted(original)])


def is_anagram(test, original):
	test_set = sorted(test.lower())
	original_set = sorted(original.lower())
	if test_set == original_set:
		return True
	else:
		return False


def is_anagram(test, original):
	t = sorted(test.lower())
	o = sorted(original.lower())
	if t == o:
		return True
	else:
		return False


def is_anagram(test, original):
	new_test = test.lower()
	new_original = original.lower()
	sortedTest = sorted(new_test)
	sortedOriginal = sorted(new_original)
	for letters in new_test:
		if letters in new_original and len(new_test) == len(new_original) and (sortedOriginal == sortedTest):
			return True
		else:
			return False


def is_anagram(test, original):
	test_word_freq = {}
	original_word_freq = {}
	test = test.lower()
	original = original.lower()
	if len(test) == len(original):
		for (idx, letter) in enumerate(test):
			if letter not in test_word_freq:
				test_word_freq[letter] = 1
			else:
				test_word_freq[letter] += 1
		for (idx, lett) in enumerate(original):
			if lett not in original_word_freq:
				original_word_freq[lett] = 1
			else:
				original_word_freq[lett] += 1
		print(original_word_freq)
		print(test_word_freq)
		for (k, v) in list(test_word_freq.items()):
			if k not in original_word_freq:
				return False
			if v != original_word_freq[k]:
				return False
		return True
	else:
		return False


def is_anagram(test, original):
	first = [i.lower() for i in test]
	second = [i.lower() for i in original]
	return sorted(first) == sorted(second)


def is_anagram(test, original):
	list_test = []
	list_original = []
	for i in test.lower():
		list_test += i
	for i in original.lower():
		list_original += i
	if len(list_test) == len(list_original):
		list_test.sort()
		list_original.sort()
		if list_test == list_original:
			return True
		else:
			return False
	else:
		return False


def is_anagram(test, original):
	return True if sorted([letter for letter in test.lower()]) == sorted([letter for letter in original.lower()]) else False


def is_anagram(test, original):
	t = list(test.lower())
	to = ''.join(sorted(t))
	o = list(original.lower())
	oo = ''.join(sorted(o))
	if to == oo:
		return True
	else:
		return False


def is_anagram(test, original):
	letterCount = dict.fromkeys('abcdefghijklmnopqrstuvwxyz', 0)
	for c in test.lower():
		letterCount[c] += 1
	for c in original.lower():
		letterCount[c] -= 1
	for value in list(letterCount.values()):
		if value != 0:
			return False
	return True


def is_anagram(a_str, b_str):
	if len(a_str) == len(b_str):
		a_list = list(a_str.lower())
		b_list = list(b_str.lower())
		for char in a_list:
			if char in b_list:
				b_list.remove(char)
		if not b_list:
			return True
		else:
			return False
	else:
		return False


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	else:
		test = test.lower()
		original = original.lower()
		counter_original = [0] * 26
		counter_test = [0] * 26
		for i in test:
			counter_test[ord(i) - 97] += 1
		for i in original:
			counter_original[ord(i) - 97] += 1
	return counter_test == counter_original


def is_anagram(test, original):
	test = test.lower()
	original = original.lower()
	newList = [ord(c) for c in test]
	newList.sort()
	newList2 = [ord(b) for b in original]
	newList2.sort()
	if newList == newList2:
		return True
	else:
		return False


def is_anagram(test, original):
	counterTest = [0] * 255
	counterOri = [0] * 255
	for i in range(len(test)):
		counterTest[ord(test[i].lower())] += 1
	for i in range(len(original)):
		counterOri[ord(original[i].lower())] += 1
	if counterOri == counterTest:
		return True
	else:
		return False


def is_anagram(test, original):
	test = test.upper()
	original = original.upper()
	if sorted(test) == sorted(original):
		return True
	else:
		return False


def is_anagram(test, original):
	if len(test) == len(original):
		test = test.lower()
		original = original.lower()
		for i in test:
			if original.find(i) == -1:
				return False
			else:
				test.replace(i, '')
				original.replace(i, '')
	else:
		return False
	return True


def is_anagram(test, original):
	counter1 = [0] * 255
	counter2 = [0] * 255
	for i in range(len(test)):
		counter1[ord(test[i].lower())] += 1
	for i in range(len(original)):
		counter2[ord(original[i].lower())] += 1
	return counter1 == counter2


def is_anagram(test, original):
	test = test.lower()
	original = original.lower()
	for x in range(len(test)):
		if test.count(test[x]) != original.count(test[x]):
			return False
	for x in range(len(original)):
		if test.count(original[x]) != original.count(original[x]):
			return False
	return True


def is_anagram(test, original):
	test = test.lower()
	original = original.lower()
	nT = len(test)
	nO = len(original)
	if nO == nT:
		counterT = [0] * (255 + 1)
		counterO = [0] * (255 + 1)
		for x in range(nT):
			counterT[ord(test[x])] += 1
			counterO[ord(original[x])] += 1
		if counterT == counterO:
			return True
		else:
			return False
	else:
		return False


def is_anagram(test, original):
	n = len(original)
	if n != len(test):
		return False
	counterTest = [0] * 255
	counterOrig = [0] * 255
	for i in range(n):
		counterTest[ord(test[i].lower())] += 1
		counterOrig[ord(original[i].lower())] += 1
	return True if ''.join(map(str, counterTest)) == ''.join(map(str, counterOrig)) else False


def is_anagram(test, original):
	return sorted([n.lower() for n in test]) == sorted([n.lower() for n in original])


def is_anagram(word_o, test_o):
	is_anagram = True
	word = word_o.lower()
	test = test_o.lower()
	if len(word) != len(test):
		is_anagram = False
	alist = list(test.lower())
	pos1 = 0
	while pos1 < len(word) and is_anagram:
		pos2 = 0
		found = False
		while pos2 < len(alist) and (not found):
			if word[pos1] == alist[pos2]:
				found = True
			else:
				pos2 = pos2 + 1
		if found:
			alist[pos2] = None
		else:
			is_anagram = False
		pos1 = pos1 + 1
	return is_anagram


def is_anagram(test, original):
	l1 = list(test.lower())
	l2 = list(original.lower())
	if len(l1) == len(l2):
		for i in l1:
			if i in l2:
				l2.remove(i)
			else:
				return False
	else:
		return False
	return True


def is_anagram(test, original):
	for i in test.lower():
		if i in original.lower() and len(test) == len(original):
			continue
		else:
			return False
	return True


def is_anagram(test, original):
	test_list = [letter1 for letter1 in test.lower()]
	orig_list = [letter2 for letter2 in original.lower()]
	if sorted(test_list) == sorted(orig_list):
		return True
	else:
		return False


def is_anagram(test, original):
	t = sorted(test.lower())
	o = sorted(original.lower())
	if t == o:
		print('true')
		return True
	else:
		print('false')
		return False


def is_anagram(test, original):
	test = [i.lower() for i in test]
	original = [j.lower() for j in original]
	test.sort()
	original.sort()
	return test == original


def is_anagram(test, original):
	test = test.lower()
	original = original.lower()
	if len(test) != len(original):
		return False
	for x in test:
		if test.count(x) == original.count(x):
			continue
		else:
			return False
	return True


def is_anagram(test, original):
	test = test.lower()
	original = original.lower()
	new_test = list(test)
	new_original = list(original)
	new_test.sort()
	new_original.sort()
	if new_test == new_original:
		return True
	return False
	pass


def is_anagram(test, original):
	return set(test.upper()) == set(original.upper()) and len(test) == len(original)


is_anagram = lambda test, original: True if sorted(original.lower()) == sorted(test.lower()) else False


def is_anagram(test, original):
	originalLower = [val for val in original.lower()]
	arr = test.lower()
	if len(arr) != len(originalLower):
		return False
	for element in arr:
		if element not in originalLower:
			return False
		else:
			originalLower.remove(element)
	return True


def is_anagram(test, original):
	n1 = len(test)
	n2 = len(original)
	if n1 != n2:
		return False
	str1 = sorted(test.lower())
	str2 = sorted(original.lower())
	for i in range(0, n1):
		if str1[i] != str2[i]:
			return False
	return True


def is_anagram(test, original):
	test_l = list(test.lower())
	original_l = list(original.lower())
	test_l.sort()
	original_l.sort()
	if test_l == original_l:
		return True
	else:
		return False


def is_anagram(test, original):
	test = list(test.lower())
	original = list(original.lower())
	if len(test) != len(original):
		return False
	for word in test:
		for word2 in original:
			if word == word2:
				original.remove(word2)
				break
	if len(original) == 0:
		return True
	else:
		return False


def is_anagram(test, original):
	a = sorted(list(test.lower()))
	b = sorted(list(original.lower()))
	if a == b:
		print(f'The word {test} is an anagram of {original}')
		return True
	else:
		print(f'Characters do not match for test case {test}, {original}')
		return False


def is_anagram(test, original):

	def to_list(string):
		listed = []
		for i in range(len(string)):
			listed.append(string[i])
		return listed
	return str(sorted(to_list(test.lower()))) == str(sorted(to_list(original.lower())))


def is_anagram(test, original):
	test = list(test.lower())
	test.sort()
	original = list(original.lower())
	original.sort()
	if original != test or len(test) != len(original):
		return False
	else:
		return True


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	test = sorted(test.lower())
	original = sorted(original.lower())
	for i in range(len(test)):
		if test[i] != original[i]:
			return False
	return True


def is_anagram(test, original):
	result = True if len(test) == len(original) else False
	for letter in test.upper():
		result = False if letter not in original.upper() else result
	return result


def is_anagram(test, original):
	if len(original) != len(test):
		return False
	test = test.lower()
	original = original.lower()
	for letter in original:
		if original.count(letter) != test.count(letter):
			return False
	return True


def is_anagram(test, original):
	if sorted(test.lower()) == sorted(original.lower()):
		return True
	elif test != original:
		return False


def is_anagram(test, original):
	test_list = sorted(list(test.lower()))
	original_list = sorted(list(original.lower()))
	if test_list == original_list:
		return True
	if test_list != original_list:
		return False


def is_anagram(test, original):
	test = test.lower()
	original = original.lower()
	t = list(test)
	o = list(original)
	t.sort()
	o.sort()
	return t == o


def is_anagram(test, original):
	t = test.lower()
	o = [*original.lower()]
	if len(t) != len(o):
		return False
	for c in t:
		if c in o:
			o.remove(c)
		else:
			return False
	return True


def is_anagram(test, original):
	if len(test) > len(original) or len(test) < len(original):
		return False
	res = ''
	counter = 0
	sortedTest = sorted(test.lower())
	sortedOriginal = sorted(original.lower())
	for i in range(0, len(sortedTest)):
		if sortedTest[i] != sortedOriginal[i]:
			res = False
			break
		else:
			res = True
	return res


from collections import Counter as C

def is_anagram(test, original):
	return C(test.lower()) == C(original.lower())


def is_anagram(test, original):
	sort1 = sorted(test.lower())
	sort2 = sorted(original.lower())
	if ''.join(sort2) == ''.join(sort1):
		return True
	else:
		return False


def is_anagram(test, original):
	theTest = test.lower()
	theOriginal = original.lower()
	if len(theTest) != len(theOriginal):
		return False
	else:
		index = 0
		lengthCheck = 0
		array = [None] * len(theTest)
		for i in theOriginal:
			array[index] = i
			index += 1
		for j in theTest:
			testLength = len(theTest)
			if j in array:
				lengthCheck += 1
			else:
				return False
		if lengthCheck == testLength:
			return True


def is_anagram(tst, org):
	tst = tst.lower()
	org = org.lower()
	if len(tst) != len(org):
		return False
	for i in org:
		if tst.count(i) != org.count(i):
			return False
	return True


def is_anagram(test, original):
	if len(test) != len(original):
		return False
	elif sorted(test.casefold()) == sorted(original.casefold()):
		return True
	else:
		return False


def is_anagram(test, original):
	letters_original = sorted(list(original.upper()))
	letters_test = sorted(list(test.upper()))
	return letters_original == letters_test


def is_anagram(test, original):
	return len(test) == len(original) and all([i in original.lower() for i in test.lower()])


def is_anagram(test, original):
	org1 = [x.lower() for x in original]
	org2 = [y.lower() for y in test]
	org1.sort()
	org2.sort()
	if org1 == org2:
		return True
	return False


def is_anagram(test, original):
	original_list = list(original.lower())
	test_list = list(test.lower())
	original_list.sort()
	test_list.sort()
	a = ''.join(test_list)
	b = ''.join(original_list)
	return a == b


def is_anagram(test, original):
	test = test.lower().replace(' ', '')
	original = original.lower().replace(' ', '')
	if len(test) != len(original):
		return False
	for letter in test:
		if letter not in original:
			return False
	for letter in original:
		if letter not in test:
			return False
	return True