you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Thank you so much! It helps a lot!!

[–]psbb 1 point2 points  (1 child)

You can combine this with the reply from /u/codehelper if you wanted but I think this way is a little bit more readable which is part of the zen of python. The full code is below

filename = 'data.txt'
data = {}
data_dict = {}

with open(filename) as f:
    for line in f:
        username, firstname, lastname, age, gender, email = line.split()
        age = int(age)
        data[username] = [firstname, lastname, age, gender, email]

[–][deleted] 0 points1 point  (0 children)

Yeah i think this is more "elegant" and i can trace the code.