w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Reading a file in python and creating a list turns out to an empty list

Try this, its most pythonic i think:

fin = open("foo1.txt")
G={}
for line in fin: # load data, create adj lists
    lst = line.split()
    lst = [int(x) for x in lst]
    G[lst[0] ]=lst[1:]
print(G)




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.