-
Notifications
You must be signed in to change notification settings - Fork 0
/
dicttest.py
82 lines (79 loc) · 1.75 KB
/
dicttest.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
70
71
72
73
74
75
76
77
78
79
80
81
82
'''dict1 = {
'A' : 12,
'B' : 15,
' ' : 111
}
d3 = {
'D' : 44
}
d2 = dict1.copy()
print(list(d2.values()))
for key in d2.keys():
d2[key] = str(d2[key]) + "1"
print(dict1)
print(d2.items())
d4 = {}
d4.update(d2)
d4.update(d3)
print(d4)'''
import json
'''hfmanTreeFile = "hfmTree.json"
initjson = open(hfmanTreeFile)
init = json.load(initjson)
print(init)
with open('tobe.txt') as f:
strr = ""
tobe = list(f.read())
print(tobe)
for t in tobe:
if(t != '\n'):
strr += init[t]
print(strr)
cf = open('CodeFile.txt','w')
cf.write(strr)
cf.close()
def decode(astr,hfmTreedict):
for key in hfmTreedict.keys():
if (astr == hfmTreedict[key]):
return key
return 0
with open('CodeFile.txt') as de:
dec = list(de.read())
decostr = ""
decolist = []
#print(dec)
for e in dec:
decostr += e
if(decode(decostr,init) !=0):
decolist.append(decode(decostr,init))
decostr = ""
print("".join(decolist))
'''
import tu
#print(type(init))
def initArc(str=str):
l = str.split(",")
h = tu.ArcNode
c = tu.ArcNode
h = c
for i in range(len(l)):
t = tu.ArcNode(int(l[i]))
c.next = t
c = c.next
return h.next
def initimg(imgfile):
initjson = open(imgfile)
init = json.load(initjson)
imgV = [tu.VNode for i in range(len(init) + 1)]
for key in init.keys():
#print(key)
imgV[int(key)] = tu.VNode(int(key))
imgV[int(key)].firstarc = initArc(init[key])
return tu.ALGraph(imgV)
'''print(imgV[1].firstarc.next.next,end="\n\n\n")
tu.outputAdjlist(imgV)
test = tu.ALGraph(imgV)
print(test.vexnum)'''
test = initimg("image.json")
vexset,arcset = tu.dfs(test,1)
print(vexset,arcset)