我正在开发一个程序,它可以确定一个图是否是强连通的。你知道吗
我在读一系列行的标准输入。你知道吗
这些行有两个或三个空格分隔的标记、源顶点和目标顶点的名称以及可选的十进制边权重。你知道吗
输入可能如下所示:
'''
Houston Washington 1000
Vancouver Houston 300
Dallas Sacramento 800
Miami Ames 2000
SanFrancisco LosAngeles
ORD PVD 1000
'''
如何读入此输入并将其添加到图表中? 我相信我会使用这样的收藏:
flights = collections.defaultdict(dict)
谢谢你的帮助!你知道吗
使用
d
作为数据,您可以使用split-your-line和'\n',然后去掉尾部的空白,并找到. With that you can slice your string to get the name and the number associated with it.
Here I've stored the data to a dictionary. You can modify it according to your requirement!
Use regular expression modules
re.sub
的最后一个匹配项来删除多余的空格。你知道吗编辑:
为了配合你的航班
相关问题 更多 >
编程相关推荐