Created
April 27, 2021 16:06
-
-
Save matthewfeickert/00f11bc92858314c9ddff83a7d95f6a2 to your computer and use it in GitHub Desktop.
Python tricks and patterns
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
# Use the generator .next method to quickly get the first non-None item in a list | |
if __name__ == "__main__": | |
item_list = [None, None, "non-None-A", "non-None-B", None] | |
item = next(item for item in item_list if item is not None) | |
assert item == "non-None-A" | |
print(item) | |
# - axes = next( | |
# - artist | |
# - for artist in [self.cls_obs, self.clsb, self.clb] | |
# - if artist is not None | |
# - ).axes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment