So the file text, which I'm supposed to transfer to a dictionary for a phonebook, looks like this:
Name1 Name2 Numbers
Name3 Name4 Numbers2
and so on..
What I've tried:
def read():
file1=open("file.txt","r")
dict={}
for line in file1:
line=line.split()
if not line:continue
dict[line[0]]=line[1:]
print(dict)
When I run it, it prints nothing.
Thank you!
Many comments to make here.
1 - You forgot to add ".read()" when you open your file.
2 - You re using reserved words for the python language. "dict" is something used by the language, so avoid using it directly. Instead name them more specifically. Avoid at all cost naming your variables with words already used by Python language.
3 - Your function does not return anything. At the end of each function, you need to specify "return" plus the object you want the function to return value.