Как разделить документ в списке с python

код:

ls = [ "There are many technical seo companies around the world but THA is recognized as a leader in it. \n\nTraditional marketing never provided better opportunity in understanding the customers need. Moreover, with old school marketing aproper analysis and handling of data was a lot difficult. As a result, the ROI and efficiency were much lower as compared to AI based marketing model. 4 key benefits are highlighted here as why seo services should use ai model over traditional approach." ]

res = ls[0].split('\n')
for n in res:
  if len(n)>0:
    print(n)

Вывод:

There are many technical seo companies around the world but THA is recognized as a leader in it. 
Traditional marketing never provided better opportunity in understanding the customers need. Moreover, with old school marketing aproper analysis and handling of data was a lot difficult. As a result, the ROI and efficiency were much lower as compared to AI based marketing model. 4 key benefits are highlighted here as why seo services should use ai model over traditional approach.

Второй вариант кода:

lst = lst[0].split('\n')
for line in lst:
    print(line)

Еще вариант :

f = open("sample.txt", "r")#вощьмем текст из файла
content_list = [line.rstrip('\n') for line in f]
f.close()
print(content_list)
+1
0
+1
0
+1
0
+1
0
+1
0

Ответить

Ваш адрес email не будет опубликован. Обязательные поля помечены *