forked from Kyoko-N/Step
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_15homework.py
40 lines (32 loc) · 885 Bytes
/
5_15homework.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
## make anagram be word
originDict = []
with open('dictionary.txt', 'r') as f:
for line in f:
originDict.append(line.strip('\n').upper())
TestCase = ['CDRA', 'ABAY', 'DOTG', 'CCOW', 'UDNBREA', '', 'apple']
targetDict = {}
for x in originDict:
sample = [0] * 26
for y in x:
sample[ord(y) - ord('A')] += 1
k = ''.join(list(map(str, sample)))
if k not in targetDict:
targetDict[k] = [x]
else:
targetDict[k].append(x)
def judge(test, tar):
global res
for i in range(26):
if test[i] < tar[i]:
return
res += targetDict[tar]
for x in TestCase:
x = x.upper()
res = []
sample = [0] * 26
for y in x:
sample[ord(y) - ord('A')] += 1
k = ''.join(list(map(str, sample)))
for tar in targetDict:
judge(k, tar)
print(res)