import re
line = "the heart was made to be broken"
line_split2 = re.split(r'[ \t\n\r, ]+',line)
def chunks(line_split2, n):
for i in xrange(0, len(line_split2), n):
yield line_split2[i:i+n]
separate_word = list(chunks(line_split2, 3))
import pprint
pprint.pprint(separate_word)
count = 0
for lines in separate_word:
count = count + 1
print count
我正在尝试合并列表以显示为句子并在它们前面显示行号。
1 the heart was
2 made to be
3 broken
有什么建议吗?