Python 两个列表合并

有两个列表,分别为:

1
2
names = ['Alice', 'Beth', 'Ceil']
numbers = ['2341', '9102', '3158']

生成一个字典:

book = {'Alice': '2341', 'Beth': '9102', 'Ceil': '3158'}

Read more

Python 按行切割文件

在遇到各种比较大的问题时候,行数过多导致打开处理会出问题,则需要切割,则可以用按行数切割的方法来处理。

代码如下:

Read more

Pyhton遍历文件夹

这是一个常用的功能,可以有两种方法,os.walkos.listdir

文档是这么解释的:

os.listdir(path)

Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries ‘.’ and ‘..’ even if they are present in the directory.

Read more

Python两个字典的合并

两个字典合并的,有几种方法

1
2
3
4
dict1={1:[1,11,111],2:[2,22,222]}
dict2={3:[3,33,333],4:[4,44,444]}
#得到如下的结果
{1:[1,11,111],2:[2,22,222],3:[3,33,333],4:[4,44,444]}
Read more

Pyhton的文件操作

​ 最近搞处理文件,各种命令搞的头晕眼花,此处做个合并,以便之后观察使用。

Read more

Python创建目录

流程如下:

  1. 判断目录是否存在os.path.exists(path)
  2. 创建多层目录os.path.makedirs(path)
  3. 创建目录os.mkdir(path)
Read more

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

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

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
Your browser is out-of-date!

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

×