-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset2.py
53 lines (41 loc) · 1.14 KB
/
set2.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import string
def set_of_string(s):
return set(s)
def new_string(s, m):
ans = ''
for elem in s:
if elem not in m:
ans += elem
return ans
def list_of_words(s):
punct = string.punctuation
s = s.split()
ans = []
for elem in s:
elem = elem.strip(punct)
ans.append(elem)
return ans
def set_of_common_words(s1, s2):
set1 = set(list_of_words(s1))
set2 = set(list_of_words(s2))
ans = []
for elem in set1:
if elem in set2:
ans.append(elem)
return (ans)
def set_of_common_words_2(s1, s2):
set1 = set(list_of_words(s1.lower()))
set2 = set(list_of_words(s2.lower()))
ans = []
for elem in set1:
if elem in set2:
ans.append(elem)
return ans
if __name__ == "__main__":
with open('text.txt', mode='r', encoding='utf-8') as f:
str1= f.read()
print(set_of_string(str1))
print(new_string(str1, {'я'}))
print(list_of_words(str1))
print(set_of_common_words(str1, 'я на солнышке лежу'))
print(set_of_common_words_2(str1, 'я на солнышке лежу'))