Created
October 6, 2017 16:32
-
-
Save maxmanders/13d09a82638d15d81d9224b02afe50d3 to your computer and use it in GitHub Desktop.
Apply multiple filters with arguments to a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def filter_list(*args): | |
filters = list(args) | |
stuff = #some Boto3 call with a list of dictionaries | |
filtered = (s for s in stuff['Foo'] | |
if all([f(s) for f in filters])) | |
return filtered | |
def filter_1(some_datetime=None): | |
return lambda s: s['CreationTime'] < some_datetime | |
def filter_2(some_datetime=None): | |
return lambda s: s['DestroyedTime'] < some_datetime | |
... | |
def filter_by_some_criteria(): | |
return filter_list(filter_1_with_some_arg, filter_2_with_some_arg...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment