- 博客(4)
- 收藏
- 关注
原创 python列表推导式
特别是当你需要使用for循环来生成一个新列表。举个例子: squared = [] for x in range(10): squared.append(x**2) 你可以使用列表推导式来简化它: squared = [x**2 for x in range(10)] ...
2019-06-10 12:26:09
372
原创 python lambda表达式
1、lambda表达式 说明:通常是在需要一个函数,但是又不想费神去命名一个函数的场合下使用,也就是指匿名函数。 例: def f ( x ,y): return x * y print(f(1,2)) 等效于: g = lambda x ,y: x * y print(g( 2 , 3 )) 2、Python提供了很多函数式编程的特性 如:map、reduce、filter、sorted等这些函...
2019-06-10 12:16:08
4318
原创 Python中Json对象处理的jsonpath-rw
1、安装 $ pip install jsonpath-rw 2、用法 from jsonpath_rw import jsonpath, parse jsonpath_expr = parse('foo[*].baz') print( [match.value for match in jsonpath_expr.find({'foo': [{'baz': 1}, {'baz': 2}]})...
2019-06-10 11:47:02
1060
原创 python类型转换
1、dict —> str 1、第一种方法(直接str转) dict = {"name":"小明","age":23} print(str(dict) >>>{'name': '小明', 'age': 23} 2、第二种方法(序列化,常用方法) dict = {"name": "小明", "age": 23} str = json.dumps(dict, indent...
2019-06-10 11:29:28
418
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人