python学习第一天
2012-03-27 18:21
387 查看
今天学习了一下python,主要是作了两个例子,总结了一下涉及到的概念。
先把写的例子放上来
先把写的例子放上来
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. import re,string is_all=[]#吧日志一条条分割 is_only={}#只有session和ip,用字典 is_fina={}#最后的结果 def is_find():#主要是用来得到is_all f=open('D:\\doc\\serachlog.txt','r') temp=f.readlines() for line in temp: is_all.append(re.split('\s\s+|\t|,',line.strip())) def is_list(ip_all): for i in range(len(ip_all)): is_only[ip_all[i][1]]=is_only[i][2] def is_select(ip_only): count=0 for values in ip_only.values(): for eachkey in ip_only.keys(): if values==ip_only[eachkey]: count=count+1 is_final[values]=count count=0 学习掌握了的知识点:
第一个。split函数的使用,用来分割一个字符串,is_all.append(re.split('\s\s+|\t|,',line.strip()))
这里面strip的作用默认的话是去掉一个字符串两端的空格,也可以用lstrip和rstrip分别来去除字符串的两边.
第二个:列表和字典。列表可以有二维的,其实和数组一样,另外就是字典,字典就是有key和values两部分,key是唯一的这个结果很重要,很多地方可以用到字典来保存数据.
第三个open一个文件不要忘记把他再close
相关文章推荐
- 1.python学习第一天-爬取我的第一个网页
- python 学习第一天
- 第一天学习python
- Python学习第一天[安装与编辑器]
- 【学习Python】第一天
- 学习python3第一天,用八皇后练练手。
- python学习第一天 搭建GUI开发环境
- 我在这里安家了,准备第一天零基础学习python
- python学习笔记之基础一(第一天)
- Python学习第一天
- python学习第一天
- Python 机器(算法)学习-----第一天
- 学习python的第一天
- python学习第一天--第一个python程序
- python学习第一天
- Python学习之心路历程------第一天:基本概念(1)
- python基础学习第一天
- Python学习第一天
- 学习第一天(python)
- Python - 3.6 学习第一天