统计一个文件中某个单词的出现次数

首先有一个最简单的方法,就是用正则匹配

1
2
3
import re
tmp = open("123.txt", "r").read()
print len(re.findall("hello", tmp))

还可以利用Counter来实现更多的功能

Read more

Python中把列表转换为字典

有以下几个方法:

1、 现在有两个列表,list1 = ['key1','key2','key3']list2 = ['1','2','3'],把他们转为这样的字典:{'key1':'1','key2':'2','key3':'3'}

Read more

Python进行URL解码

Python进行URL解码

所用模块:urllib

所用函数:urllib.unquote()

Read more

Pyhton标准模块logging

GetLogger
GetLogger() returns a reference to a logger instance with the specified name if it is provided, or root if not. The names are period-separated hierarchical structures. Multiple calls to getLogger() with the same name will return a reference to the same logger object.

Read more

Python读写json

读写中文的json数据,可以用Python中的json库来进行操作。读取可以使用json.load

Read more

Pyhton 显示时间

Python显示当前时间

可以用Pyhton提供的time模块来实现

Read more
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×