The question was to see if a word is an anagram of another word.How would you improve this? It returns True if an anagram, or False otherwise.# write the function is_anagramdef is_anagram(test, original):    if len(test) != len(original):        return False    for letter in test.lower():        if letter not in original.lower():            return False    for letter in original.lower():        if letter not in test.lower():            return False    return True
Determining if a word is an anagram of another
python;strings
The collections module provides a Counter class that can do the counting and the comparing for you:from collections import Counter>>> Counter('nana') == Counter('anna')True>>> Counter('nana') == Counter('ana')FalseCounter is basically a dictionary with items as keys and counts as values, so you can build it yourself from more primitive Python types by doing something like:def count_items(sequence):    counts = {}    for item in sequence:        counts[item] = counts.get(item, 0) + 1    return countsdef is_anagram(a, b):    return count_items(a.lower()) == count_items(b.lower())