def readPhraseIndexFromFiles (filenames):
    """Takes a list of files; reads phrases from them, with one phrase per line, ignoring blank lines 
       and lines starting with '#'. Returns a map from words to the list of phrases they are the first word of."""
    phraseIndex = dict()
    for filename in filenames:
        with open(filename,"r") as instream:
            for line in instream:
                line = line.strip()
                if (line != "" and not line.startswith("#")):
                    line   = line.lower()
                    phrase = line.split()
                    firstWord  = phrase[0]
                    phraseList = phraseIndex.get(firstWord)
                    if (phraseList == None):
                        phraseList = []
                        phraseIndex[firstWord] = phraseList
                    phraseList.append(phrase)
    # Sort each list of phrases in decreasing order of phrase length
    for phrases in phraseIndex.values():
        phrases.sort(key=lambda p: len(p),reverse=True)
    return phraseIndex