如何在不遗漏最后元素的情况下将所有行连接在一起。
zip()
似乎缺少此流中的最后一个元素。
例如:seq 0 70 | xargs -L 50 | sed 's/ /,/g'
输入:
seq 0 70 | python -c $'import sys\nfor x in zip(*[iter(sys.stdin)]*50): print(",".join(x).replace("\\n",""))\n'
输出错误:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49
每行预计50个项目,最后一个zip包含其余部分:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49
50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69
相关:
答案 0 :(得分:1)
Haskell
可能?这使用izip_longest不会在最后删除额外的项目