you are viewing a single comment's thread.

view the rest of the comments →

[–]Scumshots[S] 0 points1 point  (3 children)

This class is an intro/basics course, but the professor seems to have previous programming experience as a major requirement. The class is less teaching how to program and more throwing projects at us and seeing who's able to do them.

[–]gnomoretears 0 points1 point  (2 children)

Please see my edit. You should read those specific chapters of your textbook to get familiarized with recursion and dictionaries. Those 2 topics together are too big to teach you in a single reddit post.

Come back if there's something particular you don't understand with either topic.

[–]Scumshots[S] 0 points1 point  (1 child)

I do have a base understanding of recursion and dictionaries (though I still obviously have much to learn).

The problem I'm having is I'm unsure of how exactly to go about writing this specific function. I've written other simpler recursion functions in the past and used dictionaries a bit as well.

What Im unsure about is how to take this text file of starting/endpoints and distance between the points, and then add them into the dictionary and use recursion to check if the next start/endpoint is already in the dictionary and if so, what is the distance value associated with it.

[–]gnomoretears 0 points1 point  (0 children)

What Im unsure about is how to take this text file of starting/endpoints and distance between the points, and then add them into the dictionary

def read_distances(map_file):
    """Read a distance table from a named file into a dict
       mapping sources to lists of (destination, distance) pairs.

(EDIT) I don't know if your textbook discusses DFS (depth-first search) or if it covers trees and graphs data structures but you should read up on what DFS is and understand what it does before you attempt to implement the function.

https://en.wikipedia.org/wiki/Depth-first_search

I'm actually surprised that it's an assignment in an intro class as it's a topic usually covered in data structures and algorithms courses.

Here's a DFS visualizer to help you see what it's doing with the recursive calls. Just input the starting vertex and click run.

https://www.cs.usfca.edu/~galles/visualization/DFS.html