В test.txt у меня есть 2 строки предложений.Как отобразить номер строки предложения (линия мультикана) в первой строке?
The heart was made to be broken.
There is no surprise more magical than the surprise of being loved.
В кодах:
import re
file = open('test.txt','r')#specify file to open
data = file.readlines()
file.close()
print "---------------------------------------------------"
count = 0
for line in data:
line_split = re.findall(r'[^ \t\n\r, ]+',line)
count = count + 1
def chunks(line_split, n):
for i in xrange(0, len(line_split), n):
yield line_split[i:i+n]
separate_word = list(chunks(line_split, 8))
for i, word in enumerate(separate_word, 1):
print count, ' '.join(word)
print "---------------------------------------------------"
Результаты кодов:
---------------------------------------------------
1 The heart was made to be broken.
---------------------------------------------------
2 There is no surprise more magical than the
2 surprise of being loved.
---------------------------------------------------
есть ли возможный способ для отображения количества предложения только в первой строке?
Ожидайте результаты:
---------------------------------------------------
1 The heart was made to be broken.
---------------------------------------------------
2 There is no surprise more magical than the
surprise of being loved.
---------------------------------------------------
Дон» t добавьте название языка в заголовок - для этого используются теги. –