howto prety print list in python code example
Example 1: python print dict pretty
>>> import json
>>> print json.dumps({'a':2, 'b':{'x':3, 'y':{'t1': 4, 't2':5}}},
... sort_keys=True, indent=4)
{
"a": 2,
"b": {
"x": 3,
"y": {
"t1": 4,
"t2": 5
}
}
}
Example 2: how to print a list nicely python
# Creating a list. Can also be floats and intagers
list = ["a", "b", "c", "d", "e", "f", "g"]
# Have a for loop and then print the answer index of the variable in the loop(i)
for i in range(len(list)):
print(list[i])
# Output
a
b
c
d
e
f
g