Untangle re.findall capturing groups: 'list' object has no attribute 'join'
Question: This function highlights certain keywords in a string with color. `Fore.CYAN`
and `Fore.RESET` are from the
[Colorama](https://pypi.python.org/pypi/colorama) module.

Is there a way to insert `regex` instead of the list `["This", "words",
"annotate"]`?

    
    
    from colorama import Fore
    
    def highlight(var, keywords):
        replacement = Fore.CYAN + "\\1" + reset()
        var = re.sub("(" + "|".join(map(re.escape, keywords)) + ")", replacement, var, re.I)
            print var + Fore.RESET
    
    string = "This string contains words to annotate"
    
    highlight(string, ["This", "words", "annotate"])
    

I have tried this:

    
    
    regex_keywords = re.findall(r"(This)|(Words)|(Annotate)", string, re.I)
    
    highlight(string, regex_keywords)
    

Does not work as it complains about `'list' object has no attribute 'join'"`.


Answer: `higlight` needs any iterable over strings. You have a list of list of tuple
of strings. Remove the parentheses and forget about the tuple:

    
    
    regex_keywords = re.findall(r"This|Words|Annotate", string, re.I)
    highlight(string, regex_keywords)
    

