0

I use dijkstra algorithm and make shortest_subway_route python code.

It's main

if __name__ == '__main__':
    graph = Graph() #class define add_node,add_egde

    subway() #def use add_node,add_egde
    sub = transkor() #def read .txt and make Dictionary

    s=int(input("start>>")) #input subway_number
    d=int(input("end>>")) #input subway_number

    R=shortest_path(graph, s, d) #def view how to use subway route

    sub_num =R['return1']

    subkor = list()
    num = 0
    for s in sub_num :
        kor = sub[s]
        subkor[num] = kor
        num+=1

    print(sub_kor)    
    print("time =",R['return0'])

R['return1'] is list of subwaynumbers

I tried to save the subway number in Korean. But "subkor[num] = kor" is list assignment index out of range error.

What can I do? enter image description here

I also use "subkor.append(num) = kor" but can't assign to function call error

hanbin
  • 3
  • 2
  • I also used "subkor.append(num) = kor" can't assign to function call error – hanbin Nov 28 '17 at 15:24
  • You don't need the `if __name__ == '__main__':` as an umbrella for a toplevel script. That is just a common pattern for a module defining several fucntins and classes that can have a stand alone use, or be imported as part of another program – jsbueno Nov 28 '17 at 15:25
  • Strange, I'd expect `subkor.append(num) = kor` to crash with `SyntaxError: can't assign to function call` rather than "list assignment out of range". – Kevin Nov 28 '17 at 15:26
  • (therefore, you can just add this code to another .py file and import the things that are defined in this one) – jsbueno Nov 28 '17 at 15:26
  • what do you expect subkor.append(num) = kor to actually do? – Foon Nov 28 '17 at 17:29

0 Answers0