lehisanchez
3/20/2017 - 2:52 PM

Secret Python Message

Secret Python Message

#!/usr/bin/env python3

""" Find a secret word in a string of text

    Usage:
        python3 program.py <CHARACTERS> <TEXT>
"""
import sys
import operator


def main(characters, text):
    """ Tally the characters in a string of characters

    Args:
        characters: the list of characters to search for

        text: the string of characters to search through

    Returns:
        Prints the secret word
    """
    character_totals = dict((character,0) for character in list(characters))
    for character in characters:
        character_totals[character] = text.count(character)
        remaining_word = ''
        for character in sorted(character_totals.items(), key=operator.itemgetter(1), reverse=True):
            if character[0] != '_':
                remaining_word = remaining_word + character[0]
            else:
                break
    print(remaining_word)


if __name__ == '__main__':
    main(sys.argv[1],sys.argv[2])