secce 发表于 2017-4-21 09:12:53

Python 记录.

一, 2个长度相同的list, 如何在判断其中一个list时,得到另一组list的一些有用的数据.

>>>list1 = map(lambda x: '%s' % x,range(0,28))# len(list1) == 28
'['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27']'
>>>list2 = range(5, 33) # len(list2) == 28
''
# 大小相同...
#2个list数据依依对应,list2有可能有重复值,所以不能用字典.
#要求:
#1>查找list2中小于15,并且大于2的数字
#2>把查找到的结果返回对应list1的结果
>>>filter(lambda x : x ,map(lambda x :2 <x <15 and list1, list2))
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']



end..
页: [1]
查看完整版本: Python 记录.