python - Dictionary best data structure for train routes? -


So I have to work in a file (notepad file) to work essentially, which has a bunch of trains and time From one stop to the other, for example it would look like this:

  Stop A15 Stop B12 Stop C 9   

Now I need to go back and reach these stops and their time. I was thinking of reading in the file and storing it as a dictionary. My question is, what would be the best dictionary for this? Or is there any other dragon device that will prove to be more useful? Any thoughts would be appreciated!

I will go against the grain - and I would say that a straight flat is not the best for it.

Let's say that you have 100 stops and several pathways that are non-alphabetical and non-numeric. Think of the Paris Metro:

 Paris Subway

Try now and use a straightforward python dict to calculate the time between FDR and La Four? It includes two or more different routes and multiple options.

A or some form is a better structure. One duct is great for 1 to 1 mapping; Trees are better for rich details of nodes, which are related to each other, then you can use it to navigate some.

Since IS is a graph, it is easy to come up with a recursive example:

  def find_all_paths (article, start, end = path = []): path = path [Start] if start == end [path] do not start in the graph: return [] paths = [] for the node in graph [start]: if not in the path node: newpaths = find_all_paths (graph, node, Newpath: paths.append (newpath) returns path def min_path (graph, start, end): path = find_all_paths (graph, start, end) mt = 10 ** 99 mpath = [] print '\ all Paths: 'path to paths in paths: t = sum (article) [I] [j] i in j (path, path [1 ::]) print '\ t \ tevaluating:', path, t if t   

, 'B', 'C', 'D ['A', 'C', 'D', 'E'] 25 Evaluation: ['A'] ['A', 'B', 'D', 'E']] ['A', 'B', 'D', 'E'] 24 Best Path: A-> B: 5 B-> D: 10 D-> E: 9 Total: 24 All Paths: [['A', 'C', 'D'], ['A' Evaluation: ['A', 'C' , 'D'] 16 Evaluation: ['A', 'B', 'B', 'C', 'D'], ['A', 'B', 'D' 'B', 'C' 'D'] 20 Evaluation: ['A', 'B', 'D'] 15 Best Path: A-> B: 5b-> D: 10 Total: 15 All Paths: ['A', 'C', 'D', 'E', 'F'], ['A', 'B', 'C' ['A', 'B', 'D', 'D', 'E', 'F'] ['A', 'C', 'D', 'E', 'F' 'A', 'B', 'D', 'E', 'F']] Evaluation: 'A', 'B', 'C', 'D', 'E', 'F' , 'E', 'F'] 32 Best Path: A- & gt; B: 5b-> D: 10D-> E: 9E-> F: 8 Total: 32

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -