-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
72 lines (38 loc) · 1001 Bytes
/
test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# astring = "Hello world!"
# print(astring.index("o"))
# astring = "Hello world!"
# print(astring[3:7])
# lista= ["dsd",0,[1,2,3]]
# print (lista[2][2])
file = open("/home/linkon/Desktop/hello.txt","r")
# print (file.read())
string = file.readlines()
# print(string)
newList = list()
for each in string:
if each.find("www") == -1 and each.find(" ") == -1:
newList.append(each.replace("\n",""))
print (newList)
# data = list()
# for line in string:
# data.append(line.split("/n"))
# print(data)
# alist = string.split(" ")
# # print(alist)
aset = set(newList)
counter = dict()
for a in aset:
counter[a]=0
for a in newList:
if a in aset:
count = counter.get(a) +1
counter[a]=count
print(counter)
filew = open("/home/linkon/Desktop/out.txt","w+")
filew.write("Unique Words"+"\n")
for words in aset:
filew.write(words+'\n')
filew.write("Repeated Words"+"\n")
for key, value in counter.items():
if value > 1 :
filew.write(key+' '+str(value)+" times" +"\n")