Skip to content

Instantly share code, notes, and snippets.

@ejke
Created June 18, 2019 11:28
Show Gist options
  • Save ejke/8f80ca39a120675a108d102c304281a1 to your computer and use it in GitHub Desktop.
Save ejke/8f80ca39a120675a108d102c304281a1 to your computer and use it in GitHub Desktop.
Example of double list comprehension in python3
# Example of double list comprehension in python
# example key = some_numbers-some_more_numbers-message_id
found_keys = [key for message_id in all_messageids for key in returned_keys if key.endswith(message_id)]
print(found_keys)
# Following results in same but in the long way
found_keys = []
for key in returned_keys:
for message_id in all_messageids:
if key.endswith(message_id):
found_keys.append(key)
print(found_keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment