有两个列表,分别为:
1 | names = ['Alice', 'Beth', 'Ceil'] |
生成一个字典:
book = {'Alice': '2341', 'Beth': '9102', 'Ceil': '3158'}
有两个列表,分别为:
1 | names = ['Alice', 'Beth', 'Ceil'] |
生成一个字典:
book = {'Alice': '2341', 'Beth': '9102', 'Ceil': '3158'}
在遇到各种比较大的问题时候,行数过多导致打开处理会出问题,则需要切割,则可以用按行数切割的方法来处理。
代码如下:
这是一个常用的功能,可以有两种方法,os.walk
和os.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.
两个字典合并的,有几种方法
1 | dict1={1:[1,11,111],2:[2,22,222]} |
最近搞处理文件,各种命令搞的头晕眼花,此处做个合并,以便之后观察使用。
流程如下:
os.path.exists(path)
os.path.makedirs(path)
os.mkdir(path)
首先有一个最简单的方法,就是用正则匹配
1 | import re |
还可以利用Counter来实现更多的功能
Python版本:2.7.x
代码如下:
有以下几个方法:
1、 现在有两个列表,list1 = ['key1','key2','key3']
和list2 = ['1','2','3']
,把他们转为这样的字典:{'key1':'1','key2':'2','key3':'3'}
Update your browser to view this website correctly.&npsb;Update my browser now