Last active
April 22, 2018 13:51
-
-
Save IaroslavR/7dcb54830242a22de1869f6fd05a8d7e to your computer and use it in GitHub Desktop.
Examples of readable comprehension formatting from SO
This file contains hidden or 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
[x.id for x | |
in self.db.query(schema.allPostsUuid).execute(timeout=20) | |
if x.type == 'post' | |
and x.deleted is not False | |
and ... | |
and ...] | |
#----------------------------------------------------------------- | |
transform = lambda x: x.id | |
results = self.db.query(schema.allPostsUuid).execute(timeout=20) | |
condition = lambda x: x.deleted is not False and ... and ... | |
[transform(x) for x in results if condition(x)] | |
#---------------------------------------------------------------- | |
all_posts_uuid_query = self.db.query(schema.allPostsUuid) | |
all_posts_uuid_list = all_posts_uuid_query.execute(timeout=20) | |
all_uuid_list = [ | |
x.id | |
for x in all_posts_uuid_list | |
if ( | |
x.type == "post" | |
and | |
not x.deleted # <-- if you don't care about NULLs / None | |
) | |
] | |
#---------------------------------------------------------------- | |
non_flat = [[1,2,3], [4,5,6], [7,8]] | |
for x in non_flat: | |
if len(x) > 2 | |
for y in x: | |
y | |
[y for x in non_flat if len(x) > 2 for y in x] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment