下面这个文件名为filename,将其转化为字典
def load_road_network(filename):
dict1=dict()
dict2=dict()
add1=0
add2=0
with open('filename','r') as file:
for line in file:
line=line.strip()
if line:
if '#Intersection' in line:
lst=[]
key=line.split(':')[1]
add1=1
elif '#Roads' in line:
lst=[]
add2=1
elif add1:
lst.append([eval(x) for x in line.split(';')])
elif add2:
s=line.split(':')
dict2[eval(s[0])]=eval(s[1])
elif add1:
dict1[int(key)]=lst
add1=0
res=(dict1,dict2)
return res