This article introduces how to print out a piece of user information using a python dictionary
#log file content
alex#123#1 eric#123#1 tony#123#1
# index.py main program logic
# {'tony': [['123', '1']], 'alex': [['123', '1']], 'eric': [['123', '1']]} 这是结果,请用python实现 obj = open('log','r') line = obj.readlines() obj.close() dic = {} for item in line: item = item.strip() ele_line = item.split('#') dic[ele_line[0]] = [ele_line[1:]] print dic {'tony': [['123', '1']], 'alex': [['123', '1']], 'eric': [['123', '1']]}
The above is the detailed content of How to print out a piece of user information using a python dictionary. For more information, please follow other related articles on the PHP Chinese website!