上一页 1 ··· 52 53 54 55 56 57 58 59 60 ··· 72 下一页
摘要: Ctrl + a – go to the start of the command line Ctrl + e – go to the end of the command line Ctrl + k – delete from cursor to the end of the command li 阅读全文
posted @ 2017-06-11 16:25 2021年的顺遂平安君 阅读(234) 评论(0) 推荐(0)
摘要: Map map(function_to_apply, list_of_inputs) 设有以下代码: 这段代码实现的功能用map函数可以两行完成: 高级一点地,可以用一列函数作为输入: Filter _Filter_ creates a list of elements for which a fu 阅读全文
posted @ 2017-06-11 16:06 2021年的顺遂平安君 阅读(202) 评论(0) 推荐(0)
摘要: Map map(function_to_apply, list_of_inputs) 设有以下代码: >>> items = [1, 2, 3, 4, 5]>>> squared = []>>> for i in items:... s... 阅读全文
posted @ 2017-06-11 16:06 2021年的顺遂平安君 阅读(52) 评论(0) 推荐(0)
摘要: 在list comprehension中加入if条件判断: >>> lines = [line.rstrip() for line in open('script2.py') if line[0] == 'p']>>> lines['print(sys.... 阅读全文
posted @ 2017-06-11 15:56 2021年的顺遂平安君 阅读(60) 评论(0) 推荐(0)
摘要: 在list comprehension中加入if条件判断: 这段代码相当于: 在list comprehension中加入嵌套循环: 这段代码相当于: 阅读全文
posted @ 2017-06-11 15:56 2021年的顺遂平安君 阅读(491) 评论(0) 推荐(0)
摘要: list comprehension使代码变得简洁。下面这种常用的方法则显得过时: 事实上在使用list comprehension时,代码内部相当于执行下面操作: 在可以的使用的地方尽可能使用list comprehension,是一种地道的Python写法。另外,相比 循环, list comp 阅读全文
posted @ 2017-06-11 15:39 2021年的顺遂平安君 阅读(334) 评论(0) 推荐(0)
摘要: >>> L = [1,2,3,4,5]>>> L = [x+10 for x in L]>>> L[11, 12, 13, 14, 15] list comprehension使代码变得简洁。下面这种常用的方法则显得过时: >>> L = [1,2,3... 阅读全文
posted @ 2017-06-11 15:39 2021年的顺遂平安君 阅读(40) 评论(0) 推荐(0)
摘要: >>> E=enumerate('spam')>>> E>>> I=iter(E)>>> next(I)(0, 's')>>> next(I)(1, 'p')>>> list(enumerate('spam'))[(0, 's'), (1, 'p'), (... 阅读全文
posted @ 2017-06-11 15:32 2021年的顺遂平安君 阅读(66) 评论(0) 推荐(0)
摘要: 和`I__next__()`效果相同。 阅读全文
posted @ 2017-06-11 15:32 2021年的顺遂平安君 阅读(186) 评论(0) 推荐(0)
摘要: 和`iter(f)`类型相同,因为file object是它自身的iterator。 ` f.__next__() 'import sys\n' ` list则不是它自身的iterator,所以不能直接使用 ,必须使用一次 函数: 阅读全文
posted @ 2017-06-11 15:25 2021年的顺遂平安君 阅读(134) 评论(0) 推荐(0)
上一页 1 ··· 52 53 54 55 56 57 58 59 60 ··· 72 下一页