1

I have looked into the pprint function, which i tried below:

from pprint import pprint
a = [[1,2],[3,4]]
pprint(a) 

But it didn't give me what i want, which is:

1 2
3 4

Is there a simple way to solve this ?

2 Answers2

2

That's... not what pprint does.

for i in a:
  print ' '.join(i)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
-1

You can either do what Ignacio said or change the width of pprint:

>>> pprint.pprint([[1,2],[3,4]], width=10)
[[1, 2],
 [3, 4]]

But you would have to calculate the space that your list takes...

JBernardo
  • 32,262
  • 10
  • 90
  • 115