Skip to content

Instantly share code, notes, and snippets.

@andeoliveira
Last active March 22, 2023 04:43
Show Gist options
  • Save andeoliveira/429a922472b1d461505848ae5d519d0b to your computer and use it in GitHub Desktop.
Save andeoliveira/429a922472b1d461505848ae5d519d0b to your computer and use it in GitHub Desktop.
Operações com Sets no Python
#Operações com Sets no Python
bandas_rock_alternativo = {"Red Hot Chili Peppers", "Muse", "The Killers"}
bandas_indie_rock = {"The Killers", "Muse", "The Strokes"}
# União
print("União - Todas as bandas (Únicas) ")
print(bandas_rock_alternativo | bandas_indie_rock) #{'The Killers', 'Red Hot Chili Peppers', 'The Strokes', 'Muse'}
print("==========================================================")
# Interseção
print("Interseção - Bandas em comum no rock alternativo e indie rock")
print(bandas_rock_alternativo & bandas_indie_rock) #{'The Killers', 'Muse'}
print("==========================================================")
# Diferença
print("Diferença - Banda que está no rock alternativo mas não está no indie rock")
print(bandas_rock_alternativo - bandas_indie_rock) #{'Red Hot Chili Peppers'}
print("==========================================================")
# Diferença Simétrica
print("Diferença Simétrica - Bandas que estão apenas em rock alternativo ou apenas em indie rock")
print(bandas_rock_alternativo ^ bandas_indie_rock) #{'The Strokes', 'Red Hot Chili Peppers'}
print("==========================================================")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment