Skip to content

Instantly share code, notes, and snippets.

@RobertTalbert
Created October 6, 2023 12:15
Show Gist options
  • Save RobertTalbert/4e6170518270d8ad789aa430dcb81df7 to your computer and use it in GitHub Desktop.
Save RobertTalbert/4e6170518270d8ad789aa430dcb81df7 to your computer and use it in GitHub Desktop.
# Use basic logic commands to "fake" set operations.
# Here's union:
U = [1,2,3,4,5,6,7,8,9,10]
A = [1,2,3,4,5,6]
B = [2,4,6]
# A union B
[x for x in U if ((x in A) or (x in B))]
# A intersect B
[x for x in U if ((x in A) and (x in B))]
# Fill in below for complement, difference, Cartesian product
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment