Dictionary best data structure for train routes?

后端 未结 6 1183
北海茫月
北海茫月 2020-12-02 01:08

So I\'ve been tasked with essentially reading in a file (notepad file) that has a bunch of train stops and the time it takes to get from one stop to another. For example it

6条回答
  •  悲哀的现实
    2020-12-02 01:43

    A dictionary is suitable for doing this.

    It makes it easy for you to access the time (= value) for a given bus stop (= key).

    time_per_stop = {"Stop A": 15, "Stop B": 12, "Stop C": 9}
    

    Of course, in case you have a finite and small amount of bus stops, you could also just keep a list or tuple of stop times.

    time_per_stop_list = [15, 12, 9]
    

提交回复
热议问题