movie_person = ['小红','小明','小王','富豪_sb','美女_sb'] def filter_test(array): ret = [] for i in array: if not i.startswith('小'): # 以‘小’开头的 ret.append(i) return ret print(filter_test(movie_person)) def filter_test(array): res = [] for i in array: if not i.e
js的数组迭代器函数map和filter,可以遍历数组时产生新的数组,和python的map函数很类似1)filter是满足条件的留下,是对原数组的过滤:2)map则是对原数组的加工,映射成一一映射的新数组var xx = [1, 2, 5, 7];function pp(x){return x % 2;}function px(x){return x % 2;}var m = xx.map(pp);console.log("m = " + m);var f = xx.filter(p
python一切皆对象,linux一切皆文件,python操作文件是很常见的O/I操作,其内置来open()函数可以完成文件的基本操作: 一:使用内置open()函数操作文件,基本语法如下: with open("test.log","r") as f: #文件的打开模式为只读r a = f.readlines() #一次读取文件的所有行放入内存print(a) #显示读取到的文件全部内容print(type(a)) #显示读到的文件内容是列表,也就是要多读取到的内
''' Python --version :Python 2.7.11 Quote : https://docs.python.org/2/tutorial/datastructures.html#more-on-lists Add by camel97 2017-04 ''' 1.filter() #filter(function, sequence) returns a sequence consisting of those items from the sequence for whic
参考地址:http://www.cnblogs.com/sesshoumaru/p/6000788.html 英文文档: filter(function, iterable) Construct an iterator from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or