编辑2:(谢谢帕德雷克·坎宁安)
这是我在解释器中尝试的错误
>>> print s
Tony1
7684 dogs
Garry 2
8473 dogs
sara111
0 dogs
>>> spl = s.lstrip().splitlines()
>>>
>>> for it1, it2 in zip(spl[::2],spl[1::2]):
... print("{} {}".format(it1 ,it2))
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ValueError: zero length field name in format
编辑:
很抱歉,这没有解决我要找的问题,我需要用单词来解决,例如,我在regex上的输出如下所示:
Tony1
7684 dogs
Garry 2
8473 dogs
sara111
0 dogs
我需要它看起来像:
Tony1 7684 dogs
Garry 2 8473 dogs
sara111 0 dogs
这可能吗?你知道吗
原件:
我想做几个语句,给出标准输出,而不在语句之间看到换行符。你知道吗
具体来说,假设我有:
for item in range(1,100):
print item
输出如下所示:
1
2
3
4
.
.
.
如何让它看起来像:
1 2
3 4
5 6
7 8
使用
print item, item + 1
无法处理所有数据,zip将:或
izip_longest
对于长度不均匀的列表:rn[::2]
获取从元素0开始的每一秒元素,rn[1::2]
获取从元素1开始的每一秒元素从您的编辑中,您似乎需要将每两行合并在一起:
对于python 2.6:
从
ipython
shell它之所以有效,是因为
zip
操作的列表包含参数列表上相同迭代器的n
实例。。。你知道吗相关问题 更多 >
编程相关推荐