forked from lizaku/Programming-and-computer-instruments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_practice2.py
More file actions
25 lines (20 loc) · 1.01 KB
/
debug_practice2.py
File metadata and controls
25 lines (20 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Программа должна читать текст из файла и сообщать, есть ли в тексте хотя бы одна биграмма (два слова, стоящих в тексте друг за другом), встречающаяся больше двух раз. Регистр и знаки препинания нужно не учитывать. В программе хотя бы один раз нужно использовать list comprehensions.
import codecs, re
def open_file(title):
a = codecs.open(title, 'r', 'utf-8')
words = [word.strip(' ,.?!-:;').lower() for word in a.read().split()]
return words
def find_bigramm(words):
text = ''
for word in words:
text += word + ' '
for x in range(len(words)):
bigramm = words[x] + ' ' + words[x+1]
m = re.findall(bigramm, text, flags = re.U)
if len(m) > 2:
print(True)
break
def main():
f = open_file('text.txt')
z = find_bigramm(f)
main()