You could use some markdown here, using Markdown
and display
from the IPython.display
module.
I believe this answer may be what you're looking for.
EDIT
Based on the answer to the question you referenced to in your comment, here is some code that prints different elements on the same line, with the same color:
In [1]: class ListOfColoredStrings(object):
def __init__(self, *args):
"""
Expected input:
args = ["word_1", "color_1"], ["word_2", "color_2"]
:param args: pairs of [word, color], both given as strings
"""
self.strings = [a[0] for a in args]
self.colors = [a[1] for a in args]
def _repr_html_(self):
return ''.join( [
"<span class='listofstr' style='color:{}'>{}</span>"
.format(self.colors[i], self.strings[i])
for i in range(len(self.strings))
])
In [2]: %%html
<style type='text/css'>
span.listofstr {
margin-left: 5px
}
</style>
In [3]: ListOfColoredStrings(["hi", "red"], ["hello", "green"])
Output:
