Maegan Johnson Maegan Johnson - 1 year ago 107
Python Question

Why is my python list vertical?

Using python 3 and jupyter notebook (I have to, for class).

I have a function that creates a list by looping a number of times and appending a randomly chosen element from another list. But when I use the function, the list it gives displays each element on a new line. Why? Can I change it?

The code:

def create_board(length=32,seed=0,types=2):
Creates a one-dimensional game board of randomly placed
letters, using as many as are specified.

if types>26:
print("No, try a number smaller than 27.")


board = []
letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M",

for i in range(length):

return board

And then both




put out the created list, but with each element on a new line:






and so on.

Answer Source

This is caused by pretty printing, which is turned on by default in IPython sessions. This can be turned off in the configuration options, or during the session itself by running the pprint magic:

In [12]: %pprint
Pretty printing has been turned OFF

In [13]: %pprint
Pretty printing has been turned ON

In [14]: %pprint
Pretty printing has been turned OFF
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download