blob: cb2c28a340d3a22b0a4394aca2bc46532d0e5f27 (
plain)
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
|
def comp(f, g):
for k in g.keys():
if (k not in f.keys()):
return 0
elif (f[k] < g[k]):
return 0
return 1
def tally(f, word):
for c in word:
f[c] = 0
for c in word:
f[c] += 1
def proc(allow):
f = {}
tally(f, allow)
fh = open("004-file.txt", "r")
words = []
for x in fh:
y = x.rstrip('\r\n');
words.append(y)
ans = []
for word in words:
g = {}
tally(g, word)
if (comp(f,g)):
ans.append(word)
print("Input:", allow)
print("Output:", ans)
allow = "docgotrark"
proc(allow)
|