Цикл работает не так как мне нужно. Вот код:
import os
import re
os.chdir('E:\\test')
open_file_read = open('test.txt', 'r')
lines_total = ''
for lines in open_file_read.readlines():
lines_total += lines
compile_name = re.compile(r'[а-я А-Я \.]+')
compile_3 = re.compile(r'[0-9]+')
print(compile_3.findall(lines_total))
names_ball = {}
for elements in compile_name.findall(lines_total):
for elements2 in compile_3.findall(lines_total):
names_ball[elements] = elements2
print(names_ball)
keys_total = ''
for keys in names_ball.keys():
keys_total += keys
values_total = ''
for values in names_ball.values():
values_total += values
if int(values_total) < 3:
print(keys_total)
else:
pass
Содержимое файла test.txt:
Иванов О. 4
Петров И. 3
Дмитриев Н. 2
Смирнова О. 4
Керченских В. 5
Котов Д. 2
Бирюкова Н. 1
Данилов П. 3
Аранских В. 5
Лемонов Ю. 2
Олегова К. 4
Вывод программы:
['4', '3', '2', '4', '5', '2', '1', '3', '5', '2', '4']
{'Иванов О. ': '4', 'Петров И. ': '4', 'Дмитриев Н. ': '4', 'Смирнова О. ': '4', 'Керченских В. ': '4', 'Котов Д. ': '4', 'Бирюкова Н. ': '4', 'Данилов П. ': '4', 'Аранских В. ': '4', 'Лемонов Ю. ': '4', 'Олегова К. ': '4'}
Вывод должен быть:
{'Иванов О. ': '4', 'Петров И. ': '3', 'Дмитриев Н. ': '2', 'Смирнова О. ': '4', 'Керченских В. ': '5', 'Котов Д. ': '2', 'Бирюкова Н. ': '1', 'Данилов П. ': '3', 'Аранских В. ': '5', 'Лемонов Ю. ': '2', 'Олегова К. ': '4'}