Вы можете использовать здесь некоторую уценку, используя Markdown
и display
из модуля IPython.display
.
Я считаю, что этот ответ может быть тем, что вы ищете.
РЕДАКТИРОВАТЬ
На основе ответа на вопрос, на который вы ссылались в своем комментарии , вот какой-то код, который печатает разные элементы в одной строке с одинаковым цветом :
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"])
Вывод:
