打印压缩发电机的结果

use*_*296 0 python

任何想法如何打印

(([0.2, 0.6], [0.5, 0.8]), "10 11 {'chocolate': 10}")
(([0.0, 0.6], [0.8, 0.5]), "10 12 {'chocolate': 10}")
Run Code Online (Sandbox Code Playgroud)

如..

0.2  0.6  0.5  0.8  10  11 chocolate 10
0.0  0.6  0.8  0.5  10  12 chocolate 10
Run Code Online (Sandbox Code Playgroud)

我也设法强迫它(暂时忽略巧克力):

(([0.2, 0.6], [0.5, 0.8]), '10 11 10')
(([0.0, 0.6], [0.8, 0.5]), '10 12 10')
Run Code Online (Sandbox Code Playgroud)

如果这更容易变成

0.2  0.6  0.5  0.8  10  11  10
0.0  0.6  0.8  0.5  10  12  10
Run Code Online (Sandbox Code Playgroud)

尝试了我在其他问题上找到的但是比如

      print  '\n'.join('\t'.join(map(str,tuple(chain(*i)))) for i in s)
Run Code Online (Sandbox Code Playgroud)

这导致单词和最后的元素看起来像

 c        h      o       c        o        l      a      t    e 
Run Code Online (Sandbox Code Playgroud)

我还在努力....

Abh*_*jit 6

如果您的数据是

>>> spam=(([0.2, 0.6], [0.5, 0.8]), "10 11 {'chocolate': 10}")
Run Code Online (Sandbox Code Playgroud)

你可以干脆做

>>> print str(spam).translate(None,"([]){},\"'")
0.2 0.6 0.5 0.8 10 11 chocolate: 10
Run Code Online (Sandbox Code Playgroud)

如果要标记数据

>>> print str(spam).translate(None,"([]){},\"'").replace(' ','\t')
0.2 0.6 0.5 0.8 10  11  chocolate:  10
>>> 
Run Code Online (Sandbox Code Playgroud)

如果你在最终输出中使用大括号'{'和冒号':'你也可以

>>> ''.join(map(str,list(itertools.chain(*list(itertools.chain(*spam))))))
"0.20.60.50.810 11 {'chocolate': 10}"
Run Code Online (Sandbox Code Playgroud)

或者你现在在做什么

>>> print ''.join(map(str,list(itertools.chain(*list(itertools.chain(*spam))))))
0.20.60.50.810 11 {'chocolate': 10}
>>> 
Run Code Online (Sandbox Code Playgroud)

这类似于你的表达,努力实现,但加入tabnewlinejoin毁了这一切.

但我觉得简单和可读性明智,前一种方法会更好