-
Notifications
You must be signed in to change notification settings - Fork 0
/
RepWords.py
39 lines (36 loc) · 1.34 KB
/
RepWords.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
'''
The online English language skills learning website 'EngAtTip'
has designed an assessment. In the assessment a piece of text
is displayed to the students. The text contains space separated
words. A word is an alphabetic sequence of characters with no
whitespaces in between the characters, The students must identify
the words that are repeated in the text more than or equal to N
times. These repeated words are automatically removed by the system
before the next text in displayed to the students. The texts do
not contain any punctuation marks.
Write an algorithm to display the words that are repeated more than
or equal to Nomes in the text.
Example :
input : cat batman latt matter cat matter cat cat latt latt
output : cat latt
Explanation :
The word "cat is repeated four times and the word "Matt" is repeated t
hree times in the next Hence the words that will be removed are [cat","latt).
'''
data = input()
repeat_time = int(input())
Words_list = list()
data = data.split()
counts = dict()
for word in data:
if word not in counts:
counts[word] = 1
else:
counts[word] = counts[word] + 1
for key,value in counts.items() :
if value >= repeat_time :
Words_list.append(key)
if len(Words_list) == 0:
print('NA')
else :
print(*Words_list, sep =" ")