nagaram/cmdline.py
def pretty_print(input_word, anagrams, by_length=False):
    """Prints the anagram results sorted by score to stdout.

    Args:
        input_word: the base word we searched on
        anagrams: generator of (word, score) from anagrams_in_word
        by_length: a boolean to declare printing by length instead of score
    """

    scores = {}
    if by_length:
        noun = "tiles"
        for word, score in anagrams:
            try:
                scores[len(word)].append("{0} ({1:d})".format(word, score))
            except KeyError:
                scores[len(word)] = ["{0} ({1:d})".format(word, score)]
    else:
        noun = "points"
        for word, score in anagrams:
            try:
                scores[score].append(word)
            except KeyError:
                scores[score] = [word]

    print("Anagrams for {0}{1}:".format(input_word, " (score)" * by_length))

    if not valid_scrabble_word(input_word):
        print("{0} is not possible in Scrabble.".format(input_word))

    for key, value in sorted(scores.items(), reverse=True):
        print("{0:d} {1}: {2}".format(key, noun, ", ".join(value)))
def pretty_print(input_word, anagrams, by_length=False):
    scores = {}
    if by_length:
        noun = "tiles"
        for word, score in anagrams:
            try:
                scores[len(word)].append("{0} ({1:d})".format(word, score))
            except KeyError:
                scores[len(word)] = ["{0} ({1:d})".format(word, score)]
    else:
        noun = "points"
        for word, score in anagrams:
            try:
                scores[score].append(word)
            except KeyError:
                scores[score] = [word]

    print("Anagrams for {0}{1}:".format(input_word, " (score)" * by_length))

    if not valid_scrabble_word(input_word):
        print("{0} is not possible in Scrabble.".format(input_word))

    for key, value in sorted(scores.items(), reverse=True):
        print("{0:d} {1}: {2}".format(key, noun, ", ".join(value)))
def pretty_print ( input_word , anagrams , by_length = False ) : scores = { } if by_length : noun = "tiles" for word , score in anagrams : try : scores [ len ( word ) ] . append ( "{0} ({1:d})" . format ( word , score ) ) except KeyError : scores [ len ( word ) ] = [ "{0} ({1:d})" . format ( word , score ) ] else : noun = "points" for word , score in anagrams : try : scores [ score ] . append ( word ) except KeyError : scores [ score ] = [ word ] print ( "Anagrams for {0}{1}:" . format ( input_word , " (score)" * by_length ) ) if not valid_scrabble_word ( input_word ) : print ( "{0} is not possible in Scrabble." . format ( input_word ) ) for key , value in sorted ( scores . items ( ) , reverse = True ) : print ( "{0:d} {1}: {2}" . format ( key , noun , ", " . join ( value ) ) )
Prints the anagram results sorted by score to stdout.

    Args:
        input_word: the base word we searched on
        anagrams: generator of (word, score) from anagrams_in_word
        by_length: a boolean to declare printing by length instead of score
Prints the anagram results sorted by score to stdout .