我正在尝试从文件创建字典。我正在从第一行中提取密钥,并希望添加其余的行,而没有重复的值作为该密钥。 在此处粘贴代码,所需的输出和文件。
fh=open('lines_removed')
dictf={}
cont=fh.readlines()
for c in cont:
if "INCLUDING FILE" in c:
temp=c.split(' ')[3].strip('\'')
dictf[temp]=[]
for line in cont:
dictf[temp].append(line)
print(dictf[temp])
'template/ABC/abc.acl' : 'policy PABC
{ # ID: bug-5458563
match {
source-address any;
destination-address PQRST;
application [ TCP-53 UDP-53 ];
}
then {
permit;
}
}
# END OF FILE 'template/ABC/abc.acl''
# INCLUDING FILE 'template/ABC/abc.acl' from file './clab_srx_zp_all.acl' line 1
policy PABC {
# ID: bug-5458563
match {
source-address any;
destination-address PQRST;
application [ TCP-53 UDP-53 ];
}
then {
permit;
}
}
# END OF FILE 'template/ABC/abc.acl'
# INCLUDING FILE 'template/ABC/abc.acl' from file './clab_srx_zp_all.acl' line 1
policy PABC {
# ID: bug-5458563
match {
source-address any;
destination-address PQRST;
application [ TCP-53 UDP-53 ];
}
then {
permit;
}
}
# END OF FILE 'template/ABC/abc.acl'