Skip to content

Latest commit

 

History

History
94 lines (76 loc) · 2.13 KB

README.md

File metadata and controls

94 lines (76 loc) · 2.13 KB

Python-PrettyPrintDictionary

Prints Dictionary key-values in a human readable manner.

What it is?

Suppose you have the following dictionary: ``` dict_1 = {'a': 0, '1': {1: 'c', 2: 'd'}, '2': [1, 2, 3, 4, 5, 6]} ``` When you print this on the console you will have this: ``` >>> {'a': 0, '1': {1: 'c', 2: 'd'}, '2': [1, 2, 3, 4, 5, 6]} ``` What if you have a very larger dictionary of things that each key has an iterable object, i.e dictionary, list, ...? How does it look like?

Suppose you have the following dictionary:

dict_1 = {'a': 0, '1': {1: {'abc': [1, 2, 3, 4, 5, 6], 'efg': [7, 8, 9, 10, 100]},
                        2: {'1': {1: 'abc', 2: 'efg'}, '2': {3: 'abc'}}}, '2': [1, 2, 3, 4, 5, 6]}

if you print if normally it will be this:

{'a': 0, '1': {1: {'abc': [1, 2, 3, 4, 5, 6], 'efg': [7, 8, 9, 10, 100]}, 2: {'1': {1: 'abc', 2: 'efg'}, '2': {3: 'abc'}}}, '2': [1, 2, 3, 4, 5, 6]}

But if you use this lib it would be this(this is PyCharm Console):

Usage

Simply import the PrettyDict from pretty_dictionary module from pretty_print_dictionary package

from pretty_print_dictionary.pretty_dictionary import PrettyDict

Create your own dictionary.

my_dictionary = {0:[1,2,3], 1:['a','b']}

Create a class of PrettyDict and set your dictionary as its argument.

pd = PrettyDict(my_dictionary)

Call the ppd(Pretty Print Dictionary) method to print the dictionary

pd.ppd()

Keywords

there is 4 keywords for this module:
keyword comments value(s)
fill_char_width specifies number of chars to be indented for each level. int
fill_char specifies the char to be indented for each level. str
order specifies the color style for output. 'full', 'even', 'random'
show_level prints the level number next to the key element 'show', 'hide'