python中筛选奇数 |
您所在的位置:网站首页 › python列表筛选奇数和偶数的函数 › python中筛选奇数 |
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda : 4.5.11 typesetting : Markdown code """ @Author : 行初心 @Date : 18-9-23 @Blog : www.cnblogs.com/xingchuxin @Gitee : gitee.com/zhichengjiu """ def main(): # 建立lambda表达式 fun = lambda x: x % 2 == 1 # 产生1到20的序列 [1,20] group_num = range(1, 21, 1) # 过滤出来奇数 res = filter(fun, group_num) # 转换成列表 res_list = list(res) # 查看 print(res_list) if __name__ == '__main__': main() result /home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/DataStructure/demo.py [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] Process finished with exit code 0 resource [文档] |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |