标签:lte data highlight 分享 python image log .com 技术
从列表中提取数据除了循环外还有两种方法:过滤,列表解析式:
#!/usr/bin/env python
#coding:utf-8
#@Author:Andy
# 生成一个随机列表:并选出其中的两大于零的数
from random import  randint
data = [randint(-10, 10) for i in range(1, 10)]
print(data)
# method 1
print("filter method:", list(filter(lambda x: x >= 0, data)))
# method 2
print("list comprehension:", [x for x in data if x >= 0])
执行结果:

标签:lte data highlight 分享 python image log .com 技术
原文地址:http://www.cnblogs.com/Andy963/p/6952572.html