network={1:[2,3,4],2:[1,3,4], 3:[1,2], 4:[1,3,5], 5:[6,7,8], 6:[5,8],7:[5,6], 8:[5,6,7]}
str1='network.csv'
output = open(str1,'w')
for ii1 in network.keys():
output.write(repr(ii1)+":[")
for n in network[ii1]:
output.write(' %s,'%(repr(n)))
output.write('\b'+']\n')
output.close()
我期望的是这样的:
1:[ 2, 3, 4]
2:[ 1, 3, 4]
3:[ 1, 2]
4:[ 1, 3, 5]
5:[ 6, 7, 8]
6:[ 5, 8]
7:[ 5, 6]
8:[ 5, 6, 7]
但我得到的是:
1:[ 2, 3, 4,]
2:[ 1, 3, 4,]
3:[ 1, 2,]
4:[ 1, 3, 5,]
5:[ 6, 7, 8,]
6:[ 5, 8,]
7:[ 5, 6,]
8:[ 5, 6, 7,]
我是新手....有人可以帮忙吗?