-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple game .py
More file actions
66 lines (50 loc) · 1.76 KB
/
Copy pathsimple game .py
File metadata and controls
66 lines (50 loc) · 1.76 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
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
54
55
56
57
58
59
60
61
62
63
64
65
66
import string
from collections import Counter
# a şıkı
def remove_stop_words(input_list):
stop_words = {'a', 'an', 'the'}
punctuation_symbols = set(string.punctuation)
result_list = []
for word in input_list:
cleaned_word = ''.join(char for char in word if char not in punctuation_symbols)
if cleaned_word and cleaned_word.lower() not in stop_words:
result_list.append(cleaned_word)
return result_list
# b şıkı
def word_frequency_dictionary(word_list):
return dict(Counter(word_list))
# c şıkı
def remove_duplicates_from_dict(word_dict):
unique_words = list(word_dict.keys())
return unique_words
# d şıkı
def create_grams(liste):
if len(liste) < 3:
return [liste]
result_grams = [liste[i:i+3] for i in range(0, len(liste), 3) if i+2 < len(liste)]
if len(liste) % 3 == 2:
result_grams.append(liste[-2:])
else:
result_grams.append(liste[-1:])
return result_grams
#$####################
original_list = input("Enter a text ")
print("Original list:")
print(original_list)
original_listt = original_list.split()
########################################
resulting_list = remove_stop_words(original_listt)
print("\nA) Resulting list:")
print(resulting_list)
####################
resulting_dict = word_frequency_dictionary(resulting_list)
print("\nB) Resulting dictionary:")
print(resulting_dict)
########################################
resulting_remo = remove_duplicates_from_dict(resulting_dict)
print("\nC) Resulting removed:")
print(resulting_remo)
####################
resulting_grams = create_grams(resulting_remo)
print("\nD) Resulting grams:")
print(resulting_grams)