-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem127_Anagrams.py
54 lines (36 loc) · 1.13 KB
/
Problem127_Anagrams.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
infile = open("prob127.txt")
infile.readline()
data = infile.readlines()
infile.close()
infile2 = open("prob127_dict.txt")
dictionary = infile2.readlines()
infile2.close()
##for word in data:
## word = word.strip()
## temp_d = [string.strip() for string in dictionary if len(string.strip())==len(word)]
## count = 0
## for each in temp_d:
## flag = True
## if each != word:
## for char in word:
## if word.count(char)!=each.count(char):
## flag = False
## break
## if flag:
## count+=1
##
## print(count,end=" ")
# ALT USING SORTED WORDS
for word in data:
word = word.strip()
word_s = sorted(list(word))
temp_d = [string.strip() for string in dictionary if len(string.strip())==len(word)]
count = 0
## word_d = dict()
for each in temp_d:
flag = True
if each != word:
each = sorted(list(each))
if each == word_s:
count+=1
print(count,end=" ")