Convert multiple lines of text files to a list and parse them into a dictionary.
# Text content Rain 80000 \ n Egon 50000 \ n Yuan 30000 \ nsalary = open ("salaryinfo.txt", "r +", encoding = "UTF-8 ") salary_list = [] # defines a new list value. For line in salary. readlines (): salary_list.append (list (line. split () # The list read is appended to the salary_list value. Print (salary_list) print ("--- I am a separation line ---") salary_dict ={}# define a new dictionary value for dic in salary_list: # circular dictionary salary_dict [dic [0] = int (dic [-1]) # The left and right sides are the K of the dictionary, and the right side is the V of the dictionary, because the content of the original text is a string that is not an integer, here is an int type. # Output result! [['Alex ', '123'], ['rain', '123'], ['egon', '123'], ['yuany ', '20140901'] --- I am a separator ---- {'Alex ': 30000, 'rain': 100000, 'egon': 80000, 'yuanyuan': 50000}