Home > Net >  How do I print the value of a dictionary in color with Python?
How do I print the value of a dictionary in color with Python?

Time:08-07

I know how I can print the statements in color: print("\033[32m Hello! \033[0m") or with Rich print("[green]Hello![/green]").

But how do I print a dictionary's value(s) in color when it comes from a list? Or a dictionary's value(s) in general?

EX:

dict = {
        "greetings" : ["hello", "bonjour"],
        "goodbyes" : ["adios", "4"]
    }
newList = ["hola", "barev"]
dict.update({"greetings" : newList})
print(dict["greetings"][0])
print(dict)

The two above print statements would print in black, how would I make it print in green? What would I need to do? What packages/libraries would I need to download if needed?

CodePudding user response:

from termcolor import colored

print(colored(dict, 'green'))

CodePudding user response:

Use

$ pip install pygments

From the enter image description here

  • Related