Home > Backend Development > Python Tutorial > 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

高洛峰
Release: 2017-03-22 11:19:07
Original
2654 people have browsed it

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
Copy after login

# 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']]}
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template