本节内容:
python关联数组
某网友的一个问题,想用linuxjishu/13830.html target=_blank class=infotextkey>awk对一个文件进行处理,可是没有思路。
结果 :
python关联数组的处理代码:
#!/usr/bin/python
FD = open("/root/data","r")
R = {}
firline = FD.readline()
for line in FD.readlines():
tmp=line.split()
if tmp[0] in R:
if tmp[1] in R[tmp[0]]:
R[tmp[0]][tmp[1]][tmp[3]]=tmp[2]
else :
R[tmp[0]][tmp[1]]={}
R[tmp[0]][tmp[1]][tmp[3]]=tmp[2]
else:
R[tmp[0]]={}
R[tmp[0]][tmp[1]]={}
R[tmp[0]][tmp[1]][tmp[3]]=tmp[2]
for release in R.keys():
print "Release: " + release
for spa in R[release].keys():
print "tSPA: " + spa
for own in R[release][spa].keys():
print "tt" + R[release][spa][own] + "t" + own