Created
May 22, 2023 18:29
-
-
Save dgusoff/088705d0fedc4a4a318045cdbfb5aa35 to your computer and use it in GitHub Desktop.
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
import time | |
from datetime import date | |
greetings = [] | |
greetings.append(dict(name = 'Derek', robot = 'wire01', stamp = time.time())) | |
greetings.append(dict(name = 'Kyle', robot = 'wire02', stamp = time.time())) | |
# looking to do something like... | |
# greetings.where(x => x.name == "Derek" && x.robot == "wire01") | |
found = False | |
for greeting in greetings: | |
if greeting['name'] == "Derek" and greeting['robot'] == 'wire01' and greeting['stamp'] > time.time() - 7200: | |
found = True | |
break | |
print(found) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
filter
top level function is what you're looking for, but it's a purely functional construct alongsidemap
,reduce
, etc., not specific to just lists. Here's a succinct, readable, pythonic version: