开发者

I have a problem with pprint in python

开发者 https://www.devze.com 2023-04-06 09:10 出处:网络
I have looked into the pprint function, which i tried below: from pprint import pprint a = [[1,开发者_开发技巧2],[3,4]]

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

0

精彩评论

暂无评论...
验证码 换一张
取 消