I am suppose to write a program that returns the shortest distance from point A to point E. I coded to get the length, but I cant figure out how to actually get the points.

d = {("A","A"):0, ("A","B"):1, ("A","C"):3, ("A","D"):7 , ("A","E"):101,
("B","A"):101, ("B","B"):0, ("B","C"):42, ("B","D"):6, ("B","E"):27,
("C","A"):101, ("C","B"):101, ("C","C"):0, ("C","D"):2, ("C","E"):13,
("D","A"):101, ("D","B"):101, ("D","C"):101, ("D","D"):0, ("D","E"):5,
("E","A"):101, ("E","B"):101, ("E","C"):101, ("E","D"):101, ("E","E"):0
}
def shortestPath(Cities,Distances):
'''Returns the length of the shortest path from the first city in the list to the last city in the list, using only cities that appear in that list.'''
if len(Cities)==1: return 0
else: return min( map( lambda n: (Distances[Cities[0],Cities[n]] + shortestPath(Cities[n:],Distances)), range(1,len(Cities))) )
The answer to the input: shortestPath([“A”,”B”, “C”, “D”, “E”],d) is 10. But the program should also out put the distances, so the answer should actually be [10, [“A”, “C”, “D”, “E”]]
If you are determined to keep it in one meaty line, you can make a small change to your code:
I’m not quite sure how to where the erroneous tuple addition occurs, but from this you should be able to tweak your own solution…
NOTE: This comes with a health warning, you shouldn’t write all your code on one line, it’s hard to read, hard to debug and generally a bad idea.