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
# Eliminar con remove | |
s = {1, 2, 4} | |
s.remove(2) # s == {1,4} | |
s.remove(2) # KeyError! |
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
# Eliminar con discard(…) | |
s = {1, 2, 3, 4} | |
s.discard(3) # s == {1, 2, 4} | |
s.discard(5) # s == {1, 2, 4} |
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
# Agregar elementos de un conjunto a otro conjunto | |
A = {1, 2, 4} | |
B = {6, 4,2} | |
A.update(B) | |
print(A) # {1, 2, 4, 6} |
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
# Agregar | |
s = {1,2,3} | |
s.add(4) # s == {1,2,3,4} |
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
2 in {1,2,3} # True | |
4 in {1,2,3} # False | |
4 not in {1,2,3} # True |
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
# Conjuntos Disjuntos | |
{1, 2}.isdisjoint({3, 4}) # True | |
{1, 2}.isdisjoint({1, 4}) # False |
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
# Subconjunto | |
{1, 2}.issubset({1, 2, 3}) # True | |
{1, 2} <= {1, 2, 3} # True | |
{1, 5, 3, 4}.issubset({1, 2, 3}) # False | |
{1, 5, 3, 4} <= {1, 2, 3} # False |
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
# Superconjunto | |
{1, 2}.issuperset({1, 2, 3}) # False | |
{1, 2} >= {1, 2, 3} # False | |
{1, 2, 3, 4, 5}.issuperset({1, 2, 3}) # True | |
{1, 2, 3, 4, 5} >= {1, 2, 3} # True |
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
# Diferencia simétrica con | |
{1, 2, 3, 4}.symmetric_difference({2, 3, 5}) # {1, 4, 5} | |
{1, 2, 3, 4} ^ {2, 3, 5} # {1, 4, 5} |
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
# Diferencia | |
{1, 2, 3, 4}.difference({2, 3, 5}) # {1, 4} | |
{1, 2, 3, 4} - {2, 3, 5} # {1, 4} |
NewerOlder