M
M
molly_dolly2018-05-22 12:43:21
Python
molly_dolly, 2018-05-22 12:43:21

How to count headings in text in python?

Hello,
I'm new to python, please point me in the right direction. I have been with the program for a long time.
There are also sentences ending in !?. also headings as a separate sentence, they
can be like
Grandfather Planted
a Turnip
Planted Grandfather Turnip Planted Grandfather Turnip
The expressions I made are not working. The last one was: r'[^\w*${0}.] - python 3 version, outputs all sorts of crap.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2018-05-22
@sim3x

In [1]: import re

In [2]: t = """Посадил дед репку
   ...: ПОСАДИЛ ДЕД РЕПКУ
   ...: Посадил Дед Репку"""

In [3]: re.findall('Посадил дед репку', t)
Out[3]: ['Посадил дед репку']

In [4]: re.findall('Посадил дед репку', t, flags=re.IGNORECASE)
Out[4]: ['Посадил дед репку', 'ПОСАДИЛ ДЕД РЕПКУ', 'Посадил Дед Репку']

D
DDDsa, 2018-05-22
@DDDsa

Where sis the text of your question:

>>> re.findall('\n([\w\s]+?)(?=\n)', s)
['они могут быть как', 'Посадил дед репку', 'ПОСАДИЛ ДЕД РЕПКУ', 'Посадил Дед Репку']

It?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question