Answer the question
In order to leave comments, you need to log in
How to split text by keywords in Python?
There is a text (in the form of a school schedule with time, date, etc.), everything goes on continuously. The block of each day starts from the day of the week.
Looks like that:
Monday 06.04
1. Biology
08:30 - 09:15
§48 read https://www.yaklass.ru/TestWork/Join/KpW_hjtmxUKmI...
It is necessary to pass the test
"Structure of the nervous system and its significance"
2. Russian language
09: 25 - 10:10
write out the table p186, exercise 335
5
3. Physics
10:25 - 11:10
Repeat formulas and definitions.
3
5
4. Physical culture
11:25 - 12:10
Jumping rope
5. Algebra
12:25 - 13:10
perform No. 814, 816, learn table
4
6. Chemistry
13:25 - 14:10
solve option 2
5
7 Literature
14:20 - 15:05
read p.123-130
Tuesday 07.04
1. Russian language
08:30 - 09:15
exercise 341
Files from the teacher
, special class 8
2. Russian language
09:25 - 10:10
exercise 341
Files from the teacher 8
class
4
3. Second foreign language (German)
10:25 - 11:10 exercise
4-5 p
. Algebra 12:25 - 13:10 study the presentation, complete No. 835, 840, 844(y-g), 849(g-i) Files from the teacher reshenie_neravenstv_s_odnoy_peremennoy.
Attach completed task
4
6. Geography
13:25 - 14:10
read and prepare a retelling of paragraph 49.50.
Attach completed task
5
Answer the question
In order to leave comments, you need to log in
Just started writing in Pythonat this stage, no way, you must first master the basics of the language, solve the simplest problems, and only then take on more complex ones
If I understand your purpose correctly.
The task is solved without regexps in several lines.
Method 1: -Create a dictionary and put everything you need into it.
Instead of points, the rest of the days.
shedict = {"понедельник":[],"вторник":[], ..., "суббота":[], "воскресенье":[]}
for i in range(len(text)): #text -> список строк из расписания.
if text[i].split()[0] in shedict:
key = text[i].split()[0]
continue
else:
shedict[key].append(text[i])
print(*shedict['понедельник'], sep='\n') #Выведет расписание на понедельник
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question