简体   繁体   中英

I have a problem with pprint in python

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 ?

That's... not what pprint does.

for i in a:
  print ' '.join(i)

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM