Apply Python Filter Using Lambda Function With Multiple Arguments
Python provides filter(func, iterable) capability so you can quickly filter out rows that you want by constructing a function use lambda function. However, of all the examples I found online, the lambda function only takes one argument which is the iterator. It’s not really helpful if you cannot use a dynamic lambda with multiple arguments. Say if you have list of dicts, and you want to filter the list based on one of the key in the dict. However, you want to pass the key name and the value to the lambda function. For a simple example, you have a list like the following:
rows = [{'capacityUsed': 2, 'quantitySent': 3, 'storeId': '234'},
{'capacityUsed': 1, 'quantitySent': 2, 'storeId': '123'}]