Coloring a string in a terminal
I came up with this:

for key in bcolors:
    locals().update({key: lambda string: bcolors[key] + string + bcolors["ENDC"]})


which is almost equivalent to your code (except the function names are uppercase). There is still a function being created for every colour but it's more concise in writing.

It works for me but apparently changing locals() is a bad idea:


  Others have suggested assigning to locals(). This won't work inside a function,  where locals are accessed using the LOAD_FAST opcode, unless you have an exec statement somewhere in the function.


https://stackoverflow.com/questions/8028708/dynamically-set-local-variable-in-python


  Note: The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.


https://docs.python.org/2/library/functions.html#locals

Another way I see is to write a function like so:

def _(color):
    return lambda string: bcolors[color] + string + bcolors[color]


but you'd have to call it like this:

_("BLUE")("hello")


That's the closest I can come up with.