Answer the question
In order to leave comments, you need to log in
How to make pretty output of dictionaries to Python console?
>>>t={'a':123,'b':456}
>>>t
{'b': 456, 'a': 123}
I want output like this:
b: 456
a: 123
Guys, please tell me how to do it. Google didn't come up with anything good. Thanks in advance!
Answer the question
In order to leave comments, you need to log in
for key, value in t.items():
print("{0}: {1}".format(key,value))
dic = {"name":"value"}
# Вариант 1
import json
print(json.dumps(dic, indent=4, sort_keys=True))
# Вариант 2.1
from pprint import pprint
pprint(dic)
# Вариант 2.2
import pprint
pprint.pprint(dic)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question