diff --git a/README.md b/README.md index 193e220..36b3a40 100644 --- a/README.md +++ b/README.md @@ -38,45 +38,17 @@ np.random.rand() : 0.649617730484109 ``` -#### 2. Now, `smartprint` includes pretty print (through `pprint` module) for lists and dicts as shown below: +#### 2. `smartprint` includes pretty print (through `pprint` module and colored prints through [`rich`](https://github.com/Textualize/rich) module) for lists and dicts as shown below: ##### 2 (a) List example ```python -a = [1, 4, 5, 3, 4, "This", "is", \ - ["fun; The inspect module is"], \ - "really powerful","What",["do", [9, 8, 6],"you", "think?", 5]] -sprint (a) -``` -##### Output: -``` -List: a -[1, - 4, - 5, - 3, - 4, - 'This', - 'is', - ['fun; The inspect module is'], - 'really powerful', - 'What', - ['do', [9, 8, 6], 'you', 'think?', 5]] -``` -##### 2 (b) Dict example -```python -a = {1:2, 3:"Kumar",31:"Nishant", \ - 2.5:{1:2, 3:"Kumar",31:"Nishant", 0:"NK"}, 0:"NK"} -sprint (a) + +d = {-1:"dictionaries", 0: "are", 100:"keys", "boolean":[True, False], + 6:"printed", 50:" with sorted", "Nishant":"Kumar", \ + "numbers":[1,100,-2000,12]} +sprint (d) ``` ##### Output: -``` -Dict: a -Key: Value -{0: 'NK', - 1: 2, - 2.5: {0: 'NK', 1: 2, 3: 'Kumar', 31: 'Nishant'}, - 3: 'Kumar', - 31: 'Nishant'} - ``` +drawing ## In place print replacement diff --git a/src/smartprint/__init__.py b/src/smartprint/__init__.py index ca77a8e..825c9ed 100644 --- a/src/smartprint/__init__.py +++ b/src/smartprint/__init__.py @@ -1,6 +1,6 @@ import inspect from rich import print as rprint - +import pprint def smartprint(*argv, **kwargs): """ @@ -36,4 +36,4 @@ def helper_smartprint_list(l, extracted_code): def helper_smartprint_dict(d, extracted_code): print("Dict:", extracted_code) print("Key: Value") - rprint(dict(sorted(d.items(), key=lambda item: item[0]))) + rprint(pprint.pformat(d))