How to get filter to work with a lambda taking multiple arguments?

后端 未结 9 1061
闹比i
闹比i 2020-12-08 22:11

Using Python, am finding it difficult to get filter() to work with lambda for cases where more than 1 argument needs to be passed as is the case in the following snippet:

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 22:50

    Straight from the docs of Python Filters

    Note that filter(function, iterable) is equivalent to [item for item in iterable if function(item)] if function is not None and [item for item in iterable if item] if function is None.

    So, you can just process single arguments with Python filters. That effectively means you cannot use filters for the your example. You would have to write custom-code for the same.

提交回复
热议问题