I am trying to pretty print a dict in Jupyter Notebook.
I am using the following:
import pprint
stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
stuff.insert(0, stuff[:])
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(stuff)
However upon pressing shift+enter, no [out]
cell appear (i.e. I can't see the pretty printed output)
Any idea why this is so/ what should I change in order to see the pretty printed output?
Edit: Actually this is a python 2.7 problem - it works fine in 3.x. Have anyone tried it on python 2.7 and seen it work?
a keyboard shortcut for reformatting the current code-cell (default shortcut is Ctrl-L , can also be configured not to add the keyboard shortcut). a keyboard shortcut for reformatting the whole notebook (default shortcut is Ctrl-Shift-L , can also be configured not to add the keyboard shortcut).
Use pprint() to Pretty Print a Dictionary in Python Within the pprint module there is a function with the same name pprint() , which is the function used to pretty-print the given string or object. First, declare an array of dictionaries. Afterward, pretty print it using the function pprint.
%%writefile magic command in regular Python I just read what this does. It writes the contents of a Jupyter Cell to the specified file.
If you want to change the text cell font and font size you can type the following in a cell and hit shift+enter.
Whatever you develop is correct. The only possible reason could be, Jupyter Notebook is unable to connect to the server. If you see connecting to Kernal/server like the image below in the toolbar, try to refresh the connection or reload the page.
I used the same code and I am able to see the output. check the image below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With