# JupyterLab Dictionary Content Output Format

**URL:** <https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863>\
**Category:** JupyterLab\
**Created:** [September 4, 2020, 3:08pm UTC](https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863 "2020-09-04T15:08:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ourkid123uk](https://avatars.discourse-cdn.com/v4/letter/o/4da419/32.png) [@Ourkid123uk](https://discourse.jupyter.org/u/Ourkid123uk)\
**Post date:** [September 4, 2020, 3:08pm UTC](https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863/1 "2020-09-04T15:08:17Z")

</div>

Brand new to Python and this my first question on the forum (please be gentle **rolleyes** )

I have defined a dictionary with separate keys and values as lists, shown below;

`people = {
    "first": ["Corey", "Jane", "John"],
    "last": ["Shafer", "Doe", "Millard"],
    "email":["CoreyMSchafer@gmail.com","JaneDoe@email.com","JohnM81@hotmail.com"]
}`

When i print the contents of the dictionary in “JupyterLab” the output is then returned in the following format;

`{'first': ['Corey', 'Jane', 'John'],
 'last': ['Shafer', 'Doe', 'Millard'],
 'email': ['CoreyMSchafer@gmail.com',
  'JaneDoe@email.com',
  'JohnM81@hotmail.com']}`

When i do the same using “Spyder” the output is returned with each keys contents list on the same line, as shown below;

```auto
[python]{'first': ['Corey', 'Jane', 'John'], 'last': ['Shafer', 'Doe', 'Millard'], 'email': ['CoreyMSchafer@gmail.com', 'JaneDoe@email.com', 'JohnM81@hotmail.com']}
```

How do i get “JupyterLab” to output the contents of the dictionary the same format as “Spyder” does, all on a single line? Or at least each keys list completely on each keys line.

Must be a setting in “JupyterLabs” perhaphs?

Many thanks for taking your time, any help is really appreciated.

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [September 4, 2020, 8:26pm UTC](https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863/2 "2020-09-04T20:26:57Z")

</div>

> [@Ourkid123uk](#):
>
> How do i get “JupyterLab” to output the contents of the dictionary the same format as “Spyder” does, all on a single line? Or at least each keys list completely on each keys line.

There isn’t a true line break in the JupyterLab display. Zoom out in your browser and you should see the output of `print(people)` on one line. In Chrome, `Zoom out` is under `View`.

The following in the notebook will get closer to listing each key per line but still fails with `email` key in your provided example:

```python
display(people)

```

But if you need to control display in Jupyter there may be other ways to accomplish what you seek? For example you can add in a little lightweight python code to do better handle things as you want. For example the following will place ’ keys list completely on each keys line’ as long as your JupyterLab window isn’t too narrow:

```python
from IPython.display import Markdown, display
def printmd(string):
    display(Markdown(string))
printmd(str(people).replace("],","], \n"))

```

With that code in Jupyter, you’ll see as output:

```plaintext
{'first': ['Corey', 'Jane', 'John'],
'last': ['Shafer', 'Doe', 'Millard'],
'email': ['CoreyMSchafer@gmail.com', 'JaneDoe@email.com', 'JohnM81@hotmail.com']}

```

(I employ that `printmd()` function in other answers [here](https://discourse.jupyter.org/t/how-to-add-markdown-inside-a-function-to-pretty-print-equation/2719/2) and [here](https://discourse.jupyter.org/t/display-command-output-as-math-ipython-display-math/3125/2). Relying on the output now being markdown, I added in some [markdown syntax](https://daringfireball.net/projects/markdown/) to the string representation of the dictionary to control displaying parts more.)

---

<div class="post-metadata">

**Author:** ![Ourkid123uk](https://avatars.discourse-cdn.com/v4/letter/o/4da419/32.png) [@Ourkid123uk](https://discourse.jupyter.org/u/Ourkid123uk)\
**Post date:** [September 4, 2020, 9:26pm UTC](https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863/3 "2020-09-04T21:26:54Z")

</div>

Thank you so much fomightez. I understand this must be very basic for accomplished Notebook users.

Appreciate you taking your time to advise

---

<div class="post-metadata">

**Author:** ![D\_C](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/d_c/32/3576_2.png) [@D\_C](https://discourse.jupyter.org/u/D_C)\
**Post date:** [January 25, 2021, 6:43pm UTC](https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863/4 "2021-01-25T18:43:14Z")

</div>

one point to note here is the extra spaces before the newline, which is a markdown tip to make sure the newline is displayed.

@fomightez do you have any similar tips for formatting JSON output?  
the `display(JSON(blob, expanded=True))` that I use sometimes is a bit clunky and the results are hard to navigate.

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [January 25, 2021, 7:32pm UTC](https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863/5 "2021-01-25T19:32:14Z")

</div>

Are you using JupyterLab? (You can try it from [here](https://jupyter.org/try) without needing to install anything.) There’s a viewer built-in that will let you view a JSON file rather nicely. See [here](https://www.npmjs.com/package/@jupyterlab/json-extension) for the features included in an animation. That animation also shows using JupyterLab cells.

Sorry, I actually don’t use JSON enough to have much of a knowledge base to draw on as to what works well dealing with it in an actual cell. I am a big dan of Pandas though and so I might try the suggestions in [Analyzing JSON With Python](https://help.parsehub.com/hc/en-us/articles/219619888-Analyzing-JSON-With-Python) if I had a lot to deal with.  
There’s also [this](https://www.reddit.com/r/IPython/comments/34t4m7/lpt_print_json_in_collapsible_format_in_ipython/) and [this](https://gist.github.com/nerevar/a068ee373e22391ad3a1413b3e554fb5).

If those aren’t helping, you may want to start a new topic seeking tips.

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [February 2, 2021, 3:32am UTC](https://discourse.jupyter.org/t/jupyterlab-dictionary-content-output-format/5863/6 "2021-02-02T03:32:26Z")

</div>

On a related note, there’s pprint that is for producing aesthetically pleasing representations of your data structures, see [here](https://discourse.jupyter.org/t/how-to-change-output-style-of-a-cell-list-data-type/7738/2) for one application and some resources.  
The OP could use something like the following in combination with zooming out the browser window some degree and or hiding the navigation panel temporarily:

```python
from pprint import pprint
pprint(people, width = 230)

```
