无序记录python使用中的技巧,
centos6 安装python2.7
1 | yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget mysql-devel |
python 字典比较
json_tools.diff()
python list filter (过滤list 中含有”topic”的元素,生成一个新的字典)
list(filter(lambda x: "topic" in x , confs_list)
判断变量是否存在
1 |
|
lambda, filter, map
lambda 匿名函数
格式: fun_name = lambda x : x+2(表达式)
1 | x=lambda x:x*x if x%2==0 else x |
sort lambda (按照第三列排序)
l=[(‘b’, ‘atom’, 2), (‘c’, ‘big’, 12), (‘a’, ‘tom’, 21)]
l.sort(key=lambda l: (l[2]))
l
[(‘b’, ‘atom’, 2), (‘c’, ‘big’, 12), (‘a’, ‘tom’, 21)]