-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07_sets.py
More file actions
76 lines (56 loc) · 1.68 KB
/
07_sets.py
File metadata and controls
76 lines (56 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
### Sets ###
"""
Parecen Una lista, pero tiene Unas Cuantas
Diferencias
"""
#Creando un Set
my_set = set()
my_other_set ={}
print(type(my_set))
print(type(my_other_set))# Inicialmente es un Diccionario
print("----------//----------")
my_other_set={"Tato","Naranjo",35}
print(type(my_other_set))
print("El Tamaño es:",len(my_other_set))
#print(my_other_set[1]) #No deja Llamar a posiciones para Imprimir
#Un Set no es una Estructura Ordenada
my_other_set.add("ElTatoNaranjo")
print(my_other_set)
print("----------//-----------")
#Un Set No admite Elementos Repetidos
my_other_set.add("ElTatoNaranjo")
print(my_other_set)
print("----------//-----------")
#Sintaxis para comprobar si existe el Elemento en el Set
print("Tato" in my_other_set)
print("Tatx" in my_other_set)
print("----------//-----------")
#Como eliminar un elemento de la Lista
my_other_set.remove("Tato")
print(my_other_set)
print("----------//-----------")
#Limpiando Completamente el Set
my_other_set.clear()
print(my_other_set)
print("El Tamaño del Set es:",len(my_other_set))
print("----------//-----------")
#Hemos Eliminado completamente la variable
#del my_other_set
#print(my_other_set)
print("----------//-----------")
#Creando una Lista a Partir de un Set para acceder a una
#Posicion.
my_set = {"Tato","Naranjo", 45}
my_list = list(my_set)
print(my_list)
print(my_list[2])
print("----------//-----------")
#Unir Listas y Sets
my_other_set = {"Java","Go","Python"}
my_new_set = my_set.union(my_other_set)
print(my_new_set)
#No se unirá a si mismo ya que es un Set Duplicado
#RECUERDA: No Acepta Repetidos.
print(my_new_set.union(my_new_set))
#Hallando la diferencia entre my new Set y Set.
print(my_new_set.difference(my_set))