如何在不使用复杂列表功能的情况下返回低于特定阈值的数字列表?

时间:2018-04-16 18:12:50

标签: python

我不知道如何在不使用复杂功能的情况下做到这一点,请帮忙。这是代码的文档字符串:

 '''
 finds all numbers in the list below a certain threshold
    :param numList: a list of numbers
    :threshold: the cutoff (only numbers below this will be included)
    :returns: a new list of all numbers from numList below the threshold
 '''

1 个答案:

答案 0 :(得分:0)

一种方法

def filterList(numList, threshold):
    return list(filter(lambda x: x < threshold, numList))

另一种方法:

filteredList = [x for x in numList if x < threshold]