forked from digitalinnovationone/trilha-python-dio
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request digitalinnovationone#7 from digitalinnovationone/0…
…1_estrutura_de_dados Merge dos Exercícios da Branch "01_estrutura_de_dados"
- Loading branch information
Showing
72 changed files
with
744 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
01 - Estrutura de dados/01 - Listas/00_declarando_listas.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
frutas = ["laranja", "maca", "uva"] | ||
print(frutas) | ||
|
||
frutas = [] | ||
print(frutas) | ||
|
||
letras = list("python") | ||
print(letras) | ||
|
||
numeros = list(range(10)) | ||
print(numeros) | ||
|
||
carro = ["Ferrari", "F8", 4200000, 2020, 2900, "São Paulo", True] | ||
print(carro) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
frutas = ["maçã", "laranja", "uva", "pera"] | ||
|
||
print(frutas[0]) # maçã | ||
print(frutas[2]) # uva |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
frutas = ["maçã", "laranja", "uva", "pera"] | ||
|
||
print(frutas[-1]) # pera | ||
print(frutas[-3]) # laranja |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
matriz = [ | ||
[1, "a", 2], | ||
["b", 3, 4], | ||
[6, 5, "c"] | ||
] | ||
|
||
print(matriz[0]) # [1, "a", 2] | ||
print(matriz[0][0]) # 1 | ||
print(matriz[0][-1]) # 2 | ||
print(matriz[-1][-1]) # "c" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
lista = ["p", "y", "t", "h", "o", "n"] | ||
|
||
print(lista[2:]) # ["t", "h", "o", "n"] | ||
print(lista[:2]) # ["p", "y"] | ||
print(lista[1:3]) # ["y", "t"] | ||
print(lista[0:3:2]) # ["p", "t"] | ||
print(lista[::]) # ["p", "y", "t", "h", "o", "n"] | ||
print(lista[::-1]) # ["n", "o", "h", "t", "y", "p"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
carros = ["gol", "celta", "palio"] | ||
|
||
for carro in carros: | ||
print(carro) | ||
|
||
|
||
for indice, carro in enumerate(carros): | ||
print(f"{indice}: {carro}") |
9 changes: 9 additions & 0 deletions
9
01 - Estrutura de dados/01 - Listas/06_compreensao_de_listas.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Filtrar lista | ||
numeros = [1, 30, 21, 2, 9, 65, 34] | ||
pares = [numero for numero in numeros if numero % 2 == 0] | ||
print(pares) | ||
|
||
# Modificar valores | ||
numeros = [1, 30, 21, 2, 9, 65, 34] | ||
quadrado = [numero**2 for numero in numeros] | ||
print(quadrado) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
lista = [] | ||
|
||
lista.append(1) | ||
lista.append("Python") | ||
lista.append([40, 30, 20]) | ||
|
||
print(lista) # [1, "Python", [40, 30, 20]] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
lista = [1, "Python", [40, 30, 20]] | ||
|
||
print(lista) # [1, "Python", [40, 30, 20]] | ||
|
||
lista.clear() | ||
|
||
print(lista) # [] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lista = [1, "Python", [40, 30, 20]] | ||
|
||
lista.copy() | ||
|
||
print(lista) # [1, "Python", [40, 30, 20]] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cores = ["vermelho", "azul", "verde", "azul"] | ||
|
||
print(cores.count("vermelho")) # 1 | ||
print(cores.count("azul")) # 2 | ||
print(cores.count("verde")) # 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
linguagens = ["python", "js", "c"] | ||
|
||
print(linguagens) # ["python", "js", "c"] | ||
|
||
linguagens.extend(["java", "csharp"]) | ||
|
||
print(linguagens) # ["python", "js", "c", "java", "csharp"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
|
||
print(linguagens.index("java")) # 3 | ||
print(linguagens.index("python")) # 0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
|
||
print(linguagens.pop()) # csharp | ||
print(linguagens.pop()) # java | ||
print(linguagens.pop()) # c | ||
print(linguagens.pop(0)) # python |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
|
||
linguagens.remove("c") | ||
|
||
print(linguagens) # ["python", "js", "java", "csharp"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
|
||
linguagens.reverse() | ||
|
||
print(linguagens) # ["csharp", "java", "c", "js", "python"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
linguagens.sort() # ["c", "csharp", "java", "js", "python"] | ||
print(linguagens) | ||
|
||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
linguagens.sort(reverse=True) # ["python", "js", "java", "csharp", "c"] | ||
print(linguagens) | ||
|
||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
linguagens.sort(key=lambda x: len(x)) # ["c", "js", "java", "python", "csharp"] | ||
print(linguagens) | ||
|
||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
linguagens.sort(key=lambda x: len(x), reverse=True) # ["python", "csharp", "java", "js", "c"] | ||
print(linguagens) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
|
||
print(len(linguagens)) # 5 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
linguagens = ["python", "js", "c", "java", "csharp"] | ||
|
||
print(sorted(linguagens, key=lambda x: len(x))) # ["c", "js", "java", "python", "csharp"] | ||
print(sorted(linguagens, key=lambda x: len(x), reverse=True)) # ["python", "csharp", "java", "js", "c"] |
15 changes: 15 additions & 0 deletions
15
01 - Estrutura de dados/02 - Tuplas/00_declarando_tuplas.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
frutas = ( | ||
"laranja", | ||
"pera", | ||
"uva", | ||
) | ||
print(frutas) | ||
|
||
letras = tuple("python") | ||
print(letras) | ||
|
||
numeros = tuple([1, 2, 3, 4]) | ||
print(numeros) | ||
|
||
pais = ("Brasil",) | ||
print(pais) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
frutas = ("maçã", "laranja", "uva", "pera",) | ||
|
||
print(frutas[0]) # maçã | ||
print(frutas[2]) # uva |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
frutas = ( | ||
"maçã", | ||
"laranja", | ||
"uva", | ||
"pera", | ||
) | ||
|
||
print(frutas[-1]) # pera | ||
print(frutas[-3]) # laranja |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
matriz = ( | ||
(1, "a", 2), | ||
("b", 3, 4), | ||
(6, 5, "c"), | ||
) | ||
|
||
print(matriz[0]) # (1, "a", 2) | ||
print(matriz[0][0]) # 1 | ||
print(matriz[0][-1]) # 2 | ||
print(matriz[-1][-1]) # "c" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
tupla = ("p", "y", "t", "h", "o", "n",) | ||
|
||
print(tupla[2:]) # ("t", "h", "o", "n") | ||
print(tupla[:2]) # ("p", "y") | ||
print(tupla[1:3]) # ("y", "t") | ||
print(tupla[0:3:2]) # ("p", "t") | ||
print(tupla[::]) # ("p", "y", "t", "h", "o", "n") | ||
print(tupla[::-1]) # ("n", "o", "h", "t", "y", "p") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
carros = ( | ||
"gol", | ||
"celta", | ||
"palio", | ||
) | ||
|
||
for carro in carros: | ||
print(carro) | ||
|
||
|
||
for indice, carro in enumerate(carros): | ||
print(f"{indice}: {carro}") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cores = ( | ||
"vermelho", | ||
"azul", | ||
"verde", | ||
"azul", | ||
) | ||
|
||
print(cores.count("vermelho")) # 1 | ||
print(cores.count("azul")) # 2 | ||
print(cores.count("verde")) # 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
linguagens = ("python", "js", "c", "java", "csharp",) | ||
|
||
print(linguagens.index("java")) # 3 | ||
print(linguagens.index("python")) # 0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
linguagens = ( | ||
"python", | ||
"js", | ||
"c", | ||
"java", | ||
"csharp", | ||
) | ||
|
||
print(len(linguagens)) # 5 |
8 changes: 8 additions & 0 deletions
8
01 - Estrutura de dados/03 - Conjuntos/00_declarando_conjuntos.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
numeros = set([1, 2, 3, 1, 3, 4]) | ||
print(numeros) # {1, 2, 3, 4} | ||
|
||
letras = set("abacaxi") | ||
print(letras) # {"b", "a", "c", "x", "i"} | ||
|
||
carros = set(("palio", "gol", "celta", "palio")) | ||
print(carros) # {"gol", "celta", "palio"} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
numeros = {1, 2, 3, 2} | ||
|
||
numeros = list(numeros) | ||
|
||
print(numeros[0]) |
7 changes: 7 additions & 0 deletions
7
01 - Estrutura de dados/03 - Conjuntos/02_iterar_conjuntos.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
carros = {"gol", "celta", "palio"} | ||
|
||
for carro in carros: | ||
print(carro) | ||
|
||
for indice, carro in enumerate(carros): | ||
print(f"{indice}: {carro}") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
conjunto_a = {1, 2} | ||
conjunto_b = {3, 4} | ||
|
||
resultado = conjunto_a.union(conjunto_b) | ||
print(resultado) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
conjunto_a = {1, 2, 3} | ||
conjunto_b = {2, 3, 4} | ||
|
||
resultado = conjunto_a.intersection(conjunto_b) | ||
print(resultado) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
conjunto_a = {1, 2, 3} | ||
conjunto_b = {2, 3, 4} | ||
|
||
resultado = conjunto_a.difference(conjunto_b) | ||
print(resultado) | ||
|
||
resultado = conjunto_b.difference(conjunto_a) | ||
print(resultado) |
5 changes: 5 additions & 0 deletions
5
01 - Estrutura de dados/03 - Conjuntos/06_symmetric_difference.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
conjunto_a = {1, 2, 3} | ||
conjunto_b = {2, 3, 4} | ||
|
||
resultado = conjunto_a.symmetric_difference(conjunto_b) | ||
print(resultado) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
conjunto_a = {1, 2, 3} | ||
conjunto_b = {4, 1, 2, 5, 6, 3} | ||
|
||
resultado = conjunto_a.issubset(conjunto_b) # True | ||
print(resultado) | ||
|
||
resultado = conjunto_b.issubset(conjunto_a) # False | ||
print(resultado) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
conjunto_a = {1, 2, 3} | ||
conjunto_b = {4, 1, 2, 5, 6, 3} | ||
|
||
resultado = conjunto_a.issuperset(conjunto_b) # False | ||
print(resultado) | ||
|
||
resultado = conjunto_b.issuperset(conjunto_a) # True | ||
print(resultado) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
conjunto_a = {1, 2, 3, 4, 5} | ||
conjunto_b = {6, 7, 8, 9} | ||
conjunto_c = {1, 0} | ||
|
||
resultado = conjunto_a.isdisjoint(conjunto_b) # True | ||
print(resultado) | ||
|
||
resultado = conjunto_a.isdisjoint(conjunto_c) # False | ||
print(resultado) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sorteio = {1, 23} | ||
|
||
sorteio.add(25) # {1, 23, 25} | ||
print(sorteio) | ||
|
||
sorteio.add(42) # {1, 23, 25, 42} | ||
print(sorteio) | ||
|
||
sorteio.add(25) # {1, 23, 25, 42} | ||
print(sorteio) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sorteio = {1, 23} | ||
|
||
print(sorteio) # {1,23} | ||
|
||
sorteio.clear() | ||
|
||
print(sorteio) # {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sorteio = {1, 23} | ||
|
||
print(sorteio) # {1, 23} | ||
|
||
sorteio.copy() | ||
|
||
print(sorteio) # {1, 23} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
numeros = {1, 2, 3, 1, 2, 4, 5, 5, 6, 7, 8, 9, 0} | ||
|
||
print(numeros) # {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} | ||
|
||
numeros.discard(1) | ||
numeros.discard(45) | ||
|
||
print(numeros) # {2, 3, 4, 5, 6, 7, 8, 9, 0} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
numeros = {1, 2, 3, 1, 2, 4, 5, 5, 6, 7, 8, 9, 0} | ||
|
||
print(numeros) # {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} | ||
print(numeros.pop()) # 0 | ||
print(numeros.pop()) # 1 | ||
print(numeros) # {2, 3, 4, 5, 6, 7, 8, 9} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
numeros = {1, 2, 3, 1, 2, 4, 5, 5, 6, 7, 8, 9, 0} | ||
|
||
print(numeros) # {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} | ||
print(numeros.remove(0)) # 0 | ||
print(numeros) # {1, 2, 3, 4, 5, 6, 7, 8, 9} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
numeros = {1, 2, 3, 1, 2, 4, 5, 5, 6, 7, 8, 9, 0} | ||
|
||
print(len(numeros)) # 10 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
numeros = {1, 2, 3, 1, 2, 4, 5, 5, 6, 7, 8, 9, 0} | ||
|
||
print(1 in numeros) # True | ||
print(10 in numeros) # False |
8 changes: 8 additions & 0 deletions
8
01 - Estrutura de dados/04 - Dicionários/00_declarando_dicionarios.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pessoa = {"nome": "Guilherme", "idade": 28} | ||
print(pessoa) | ||
|
||
pessoa = dict(nome="Guilherme", idade=28) | ||
print(pessoa) | ||
|
||
pessoa["telefone"] = "3333-1234" # {"nome": "Guilherme", "idade": 28, "telefone": "3333-1234"} | ||
print(pessoa) |
11 changes: 11 additions & 0 deletions
11
01 - Estrutura de dados/04 - Dicionários/01_acessando_dados.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
dados = {"nome": "Guilherme", "idade": 28, "telefone": "3333-1234"} | ||
|
||
print(dados["nome"]) # "Guilherme" | ||
print(dados["idade"]) # 28 | ||
print(dados["telefone"]) # "3333-1234" | ||
|
||
dados["nome"] = "Maria" | ||
dados["idade"] = 18 | ||
dados["telefone"] = "9988-1781" | ||
|
||
print(dados) # {"nome": "Maria", "idade": 18, "telefone": "9988-1781"} |
Oops, something went wrong.