+ 1

How to print dictionary like table format?

d={"apple":{"num": 3}, "Orange":{"num": 1}} how to print like this: >>> fruit num apple 3 Orange 1

4th Mar 2017, 6:03 PM
hamid
hamid - avatar
2 Answers
+ 3
for key, value in d.items(): print(key + "\t" + str (value["num"])) str.format() would probably be better though.
4th Mar 2017, 6:40 PM
ChaoticDawg
ChaoticDawg - avatar
0
for i in d: print('\t'+i+'\t\t\t\t'+str(d['num']))
4th Mar 2017, 7:52 PM
vishnu
vishnu - avatar