Dictionary best data structure for train routes?

后端 未结 6 1166
北海茫月
北海茫月 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:28

    A dict is perfectly acceptable in this situation. In fact, if a database is unavailable to you and you're interested in reusing this dictionary in the future, you could pickle the object and use it in another script:

    import pickle
    
    output = open('my_pickled_dict', 'wb')
    pickle.dumb(my_dict, output)
    output.close
    

    And then in your next script:

    import pickle
    
    my_pickled_file = open('my_pickled_dict', 'rb')
    my_dict = pickle.load(my_pickled_file)
    

提交回复
热议问题