Home  >  Article  >  Backend Development  >  How to print out a piece of user information using a python dictionary

How to print out a piece of user information using a python dictionary

高洛峰
高洛峰Original
2017-03-22 11:19:072638browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn