У меня есть длинная строка (несколько абзацев), которую нужно разбить на список строк. Определение того, что составляет «линию», основано на:
- Количество символов в строке меньше или равно X (где X - фиксированное количество столбцов в строке _)
- ИЛИ, есть новая строка в исходной строке (которая заставит создать новую "строку".
Я знаю, что могу сделать это алгоритмически, но мне было интересно, есть ли у Python что-то, что может обработать этот случай. По сути, это перенос слов.
И, кстати, выходные строки должны быть разбиты по границам слов, а не по символам.
Вот пример ввода и вывода:
Ввод:
"Within eight hours of Wilson's outburst, his Democratic opponent, former-Marine Rob Miller, had received nearly 3,000 individual contributions raising approximately $100,000, the Democratic Congressional Campaign Committee said.
Wilson, a conservative Republican who promotes a strong national defense and reining in the size of government, won a special election to the House in 2001, succeeding the late Rep. Floyd Spence, R-S.C. Wilson had worked on Spence's staff on Capitol Hill and also had served as an intern for Sen. Strom Thurmond, R-S.C."
Выход:
"Within eight hours of Wilson's outburst, his"
"Democratic opponent, former-Marine Rob Miller,"
" had received nearly 3,000 individual "
"contributions raising approximately $100,000,"
" the Democratic Congressional Campaign Committee"
" said."
""
"Wilson, a conservative Republican who promotes a "
"strong national defense and reining in the size "
"of government, won a special election to the House"
" in 2001, succeeding the late Rep. Floyd Spence, "
"R-S.C. Wilson had worked on Spence's staff on "
"Capitol Hill and also had served as an intern"
" for Sen. Strom Thurmond, R-S.C."