Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 01 - Estrutura de dados/01 - Listas/00_declarando_listas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
letras = list("python")
print(letras)

numeros = list(range(10))
numeros = list(range(1,11,2))
print(numeros)

carro = ["Ferrari", "F8", 4200000, 2020, 2900, "São Paulo", True]
carro = ["Ferrari", "F8", "49200-000", 49200.00, 2020, 2900, "São Paulo", True]
print(carro)
1 change: 1 addition & 0 deletions 01 - Estrutura de dados/01 - Listas/03_matriz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
print(matriz[0][0]) # 1
print(matriz[0][-1]) # 2
print(matriz[-1][-1]) # "c"
print(matriz[0][1]) # a
6 changes: 3 additions & 3 deletions 01 - Estrutura de dados/01 - Listas/05_iterar_listas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
carros = ["gol", "celta", "palio"]
carros = ["gol", "celta", "palio", "verona", "civic", "corolla", "hb20"]

for carro in carros:
print(carro)


for indice, carro in enumerate(carros):
print(f"{indice}: {carro}")
for numera, carro in enumerate(carros):
print(f"{numera}: {carro}")
27 changes: 24 additions & 3 deletions 01 - Estrutura de dados/01 - Listas/06_compreensao_de_listas.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
# Filtrar lista
# Filtrar lista (1) - Comprehension
numeros = [1, 30, 21, 2, 9, 65, 34]
pares = [numero for numero in numeros if numero % 2 == 0]
print(pares)
impares = [numero for numero in numeros if numero % 2 != 0]
print(f"Pares: {pares}")
print(f"Impares: {impares}")

# Modificar valores
# Filtrar lista (2)
numeros = [1, 30, 21, 2, 9, 65, 34]
pares = []
impares = []
for numero in numeros:
if numero % 2 == 0:
pares.append(numero)
else:
impares.append(numero)
print(f"Pares: {pares}")
print(f"Impares: {impares}")

# Modificar valores (1)
numeros = [1, 30, 21, 2, 9, 65, 34]
quadrado = [numero**2 for numero in numeros]
print(quadrado)

# Modificar valores (2)
numeros = [1, 30, 21, 2, 9, 65, 34]
quadrado = []
for numero in numeros:
quadrado.append(numero**2)
print(quadrado)
4 changes: 2 additions & 2 deletions 01 - Estrutura de dados/01 - Listas/10_count.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cores = ["vermelho", "azul", "verde", "azul"]
cores = ["verde", "vermelho", "azul", "verde", "azul"]

print(cores.count("vermelho")) # 1
print(cores.count("azul")) # 2
print(cores.count("verde")) # 1
print(cores.count("verde")) # 2
7 changes: 5 additions & 2 deletions 01 - Estrutura de dados/01 - Listas/11_extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

print(linguagens) # ["python", "js", "c"]

linguagens.extend(["java", "csharp"])
linguagens.extend(["java", "csharp", "js"])

print(linguagens) # ["python", "js", "c", "java", "csharp", "js"]
# Extendendo uma lista com outra lista


print(linguagens) # ["python", "js", "c", "java", "csharp"]
3 changes: 2 additions & 1 deletion 01 - Estrutura de dados/01 - Listas/12_index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
linguagens = ["python", "js", "c", "java", "csharp"]

# Exemplo de uso do método index
print(linguagens.index("c")) # 2
print(linguagens.index("java")) # 3
print(linguagens.index("python")) # 0
10 changes: 9 additions & 1 deletion 01 - Estrutura de dados/01 - Listas/13_pop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
linguagens = ["python", "js", "c", "java", "csharp"]
linguagens = ["python", "js", "c#", "c", "java", "csharp"]
# Exemplo de uso do método pop

print(linguagens.pop()) # csharp
print(linguagens.pop()) # java
print(linguagens.pop()) # c
print(linguagens.pop(0)) # python
print(linguagens.pop(0)) # js
print(linguagens.pop(0)) # c#





3 changes: 2 additions & 1 deletion 01 - Estrutura de dados/01 - Listas/14_remove.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
linguagens = ["python", "js", "c", "java", "csharp"]

linguagens.remove("c")
linguagens.remove("js")

print(linguagens) # ["python", "js", "java", "csharp"]
print(linguagens) # ["python", "java", "csharp"]
2 changes: 1 addition & 1 deletion 01 - Estrutura de dados/01 - Listas/15_reverse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
linguagens = ["python", "js", "c", "java", "csharp"]
print(linguagens) # ["python", "js", "c", "java", "csharp"]

linguagens.reverse()

print(linguagens) # ["csharp", "java", "c", "js", "python"]
4 changes: 2 additions & 2 deletions 01 - Estrutura de dados/01 - Listas/17_len.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
linguagens = ["python", "js", "c", "java", "csharp"]
linguagens = ["python", "js", "c", "java", "csharp", "c++"]

print(len(linguagens)) # 5
print(len(linguagens)) # 6
3 changes: 3 additions & 0 deletions 01 - Estrutura de dados/01 - Listas/18_sorted.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

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"]

print(sorted(linguagens)) # ["c", "csharp", "java", "js", "python"]
print(sorted(linguagens, reverse=True)) # ["python", "js", "java", "csharp", "c"]
4 changes: 3 additions & 1 deletion 01 - Estrutura de dados/02 - Tuplas/00_declarando_tuplas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"laranja",
"pera",
"uva",
"mamão"
)
print(frutas)
# Tuplas são imutáveis, ou seja, não podem ser alteradas após a criação

letras = tuple("python")
letras = tuple("python-3.10")
print(letras)

numeros = tuple([1, 2, 3, 4])
Expand Down
1 change: 1 addition & 0 deletions 01 - Estrutura de dados/02 - Tuplas/09_len.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
)

print(len(linguagens)) # 5

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@

carros = set(("palio", "gol", "celta", "palio"))
print(carros) # {"gol", "celta", "palio"}

linguagens = {"python", "js", "c", "c", "java", "python", "csharp"}
print(linguagens) # {"python", "js", "c", "java", "csharp"}
# Conjuntos não possuem ordem, então a ordem de impressão pode variar

5 changes: 5 additions & 0 deletions 01 - Estrutura de dados/03 - Conjuntos/01_acessando_dados.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
numeros = list(numeros)

print(numeros[0])
print(numeros[1])
print(numeros[2])
print(numeros[-1]) # 3
# Conjuntos não possuem ordem, então o índice pode não corresponder ao esperado

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
carros = {"gol", "celta", "palio"}
carros = {"gol", "celta", "gol", "palio"}

for carro in carros:
print(carro)
Expand Down
6 changes: 5 additions & 1 deletion 01 - Estrutura de dados/03 - Conjuntos/03_union.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
conjunto_a = {1, 2}
conjunto_b = {3, 4}
conjunto_c = {5, 6}
# Unindo dois conjuntos

resultado = conjunto_a.union(conjunto_b, conjunto_c)
# Unindo três conjuntos

resultado = conjunto_a.union(conjunto_b)
print(resultado)
5 changes: 4 additions & 1 deletion 01 - Estrutura de dados/03 - Conjuntos/04_intersection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
conjunto_a = {1, 2, 3}
conjunto_b = {2, 3, 4}
conjunto_c = {2, 3, 4}
# Intersecção entre dois conjuntos

resultado = conjunto_a.intersection(conjunto_b)
resultado = conjunto_a.intersection(conjunto_b, conjunto_c)
# Intersecção entre três conjuntos
print(resultado)
12 changes: 10 additions & 2 deletions 01 - Estrutura de dados/03 - Conjuntos/05_difference.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
conjunto_a = {1, 2, 3}
conjunto_b = {2, 3, 4}
conjunto_c = {2, 3, 5}
# Diferença entre dois conjuntos

resultado = conjunto_a.difference(conjunto_b)
resultado = conjunto_a.difference(conjunto_b, conjunto_c)
# Diferença entre três conjuntos
print(resultado)

resultado = conjunto_b.difference(conjunto_a)
resultado = conjunto_b.difference(conjunto_a, conjunto_c)
# Diferença entre três conjuntos
print(resultado)

resultado = conjunto_c.difference(conjunto_a, conjunto_b)
# Diferença entre três conjuntos
print(resultado)
9 changes: 9 additions & 0 deletions 01 - Estrutura de dados/03 - Conjuntos/07_issubset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
conjunto_a = {1, 2, 3}
conjunto_b = {4, 1, 2, 5, 6, 3}
conjunto_c = {1, 2, 3, 4, 5}
# Verifica se um conjunto é subconjunto de outro

resultado = conjunto_a.issubset(conjunto_b) # True
print(resultado)

resultado = conjunto_b.issubset(conjunto_a) # False
print(resultado)

resultado = conjunto_c.issubset(conjunto_a) # False
print(resultado)

resultado = conjunto_a.issubset(conjunto_c) # True
print(resultado)

4 changes: 3 additions & 1 deletion 01 - Estrutura de dados/03 - Conjuntos/14_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
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}
print(numeros.pop()) # 2
print(numeros.pop()) # 3
print(numeros) # {4, 5, 6, 7, 8, 9}
4 changes: 3 additions & 1 deletion 01 - Estrutura de dados/03 - Conjuntos/15_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

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}
print(numeros.remove(1)) # 1
print(numeros.remove(5)) # 2
print(numeros) # {2, 3, 4, 6, 7, 8, 9}
2 changes: 2 additions & 0 deletions 01 - Estrutura de dados/03 - Conjuntos/16_len.py
Original file line number Diff line number Diff line change
@@ -1,3 +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(len(numeros)) # 10
3 changes: 3 additions & 0 deletions 01 - Estrutura de dados/03 - Conjuntos/17_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

print(1 in numeros) # True
print(10 in numeros) # False
print(0 in numeros) # True
print("a" in numeros) # False
print(5 in numeros) # True
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
pessoa = {"nome": "Guilherme", "idade": 28}
# Declarando um dicionário
print(pessoa)

pessoa = dict(nome="Guilherme", idade=28)
print(pessoa)

pessoa["telefone"] = "3333-1234" # {"nome": "Guilherme", "idade": 28, "telefone": "3333-1234"}
pessoa["endereco"] = "Rua A, 123" # {"nome": "Guilherme", "idade": 28, "telefone": "3333-1234", "endereco": "Rua A, 123"}
pessoa["idade"] = 29 # Atualizando o valor da chave "idade"
print(pessoa)
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

telefone = contatos["giovanna@gmail.com"]["telefone"] # "3443-2121"
print(telefone)

nome = contatos["melaine@gmail.com"]["nome"] # "Melaine"
print(nome)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"melaine@gmail.com": {"nome": "Melaine", "telefone": "3333-7766"},
}

print("=" * 70)
for chave in contatos:
print(chave, contatos[chave])

print("=" * 100)
print("=" * 70)
# Iterando sobre as chaves e valores do dicionário

for chave, valor in contatos.items():
print(chave, valor)
print("=" * 70)
2 changes: 2 additions & 0 deletions 01 - Estrutura de dados/04 - Dicionários/05_copy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
contatos = {"guilherme@gmail.com": {"nome": "Guilherme", "telefone": "3333-2221"}}

copia = contatos.copy()
print(copia)

copia["guilherme@gmail.com"] = {"nome": "Gui"}

print(contatos["guilherme@gmail.com"]) # {"nome": "Guilherme", "telefone": "3333-2221"}
Expand Down
2 changes: 1 addition & 1 deletion 01 - Estrutura de dados/04 - Dicionários/07_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
resultado = contatos.get("chave") # None
print(resultado)

resultado = contatos.get("chave", {}) # {}
resultado = contatos.get("chave", {"Não há a chave no dicionario"}) # {"Não há a chave no dicionario"}
print(resultado)

resultado = contatos.get(
Expand Down
11 changes: 9 additions & 2 deletions 01 - Estrutura de dados/04 - Dicionários/09_keys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
contatos = {"guilherme@gmail.com": {"nome": "Guilherme", "telefone": "3333-2221"}}
contatos = {
"guilherme@gmail.com": {"nome": "Guilherme", "telefone": "3333-2221"},
"giovanna@gmail.com": {"nome": "Giovanna", "telefone": "3443-2121"},
"chappie@gmail.com": {"nome": "Chappie", "telefone": "3344-9871"},
"melaine@gmail.com": {"nome": "Melaine", "telefone": "3333-7766"},
}
# Retorna as chaves do dicionário

resultado = contatos.keys() # dict_keys(['guilherme@gmail.com'])
resultado = contatos.keys()
# dict_keys(['guilherme@gmail.com', 'giovanna@gmail.com', 'chappie@gmail.com', 'melaine@gmail.com'])
print(resultado)
3 changes: 3 additions & 0 deletions 01 - Estrutura de dados/04 - Dicionários/10_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

resultado = contatos.pop("guilherme@gmail.com", {}) # {}
print(resultado)

resultado = contatos.pop("guilherme@gmail.com", "Não encontrou") # 'Não encontrou'
print(resultado)
4 changes: 3 additions & 1 deletion 01 - Estrutura de dados/04 - Dicionários/14_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@

resultado = (
contatos.values()
) # dict_values([{'nome': 'Guilherme', 'telefone': '3333-2221'}, {'nome': 'Giovanna', 'telefone': '3443-2121'}, {'nome': 'Chappie', 'telefone': '3344-9871'}, {'nome': 'Melaine', 'telefone': '3333-7766'}]) # noqa
)
# dict_values([{'nome': 'Guilherme', 'telefone': '3333-2221'}, {'nome': 'Giovanna', 'telefone': '3443-2121'},
# {'nome': 'Chappie', 'telefone': '3344-9871'}, {'nome': 'Melaine', 'telefone': '3333-7766'}]) # noqa
print(resultado)
4 changes: 3 additions & 1 deletion 01 - Estrutura de dados/04 - Dicionários/16_del.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
del contatos["guilherme@gmail.com"]["telefone"]
del contatos["chappie@gmail.com"]

# {'guilherme@gmail.com': {'nome': 'Guilherme'}, 'giovanna@gmail.com': {'nome': 'Giovanna', 'telefone': '3443-2121'}, 'melaine@gmail.com': {'nome': 'Melaine', 'telefone': '3333-7766'}} # noqa
# {'guilherme@gmail.com': {'nome': 'Guilherme'},
# 'giovanna@gmail.com': {'nome': 'Giovanna', 'telefone': '3443-2121'},
# 'melaine@gmail.com': {'nome': 'Melaine', 'telefone': '3333-7766'}} # noqa
print(contatos)
6 changes: 3 additions & 3 deletions 01 - Estrutura de dados/05 - Funções/00_primeira_funcao.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def exibir_mensagem():
print("Olá mundo!")
def exibir_mensagem_1():
print("Olá mundo BRABO!")


def exibir_mensagem_2(nome):
Expand All @@ -10,7 +10,7 @@ def exibir_mensagem_3(nome="Anônimo"):
print(f"Seja bem vindo {nome}!")


exibir_mensagem()
exibir_mensagem_1()
exibir_mensagem_2(nome="Guilherme")
exibir_mensagem_3()
exibir_mensagem_3(nome="Chappie")
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ def criar_carro(modelo, ano, placa, /, marca, motor, combustivel):


criar_carro("Palio", 1999, "ABC-1234", marca="Fiat", motor="1.0", combustivel="Gasolina")
criar_carro(modelo="Palio", ano=1999, placa="ABC-1234", marca="Fiat", motor="1.0", combustivel="Gasolina") # inválido
# criar_carro(modelo="Palio", ano=1999, placa="ABC-1234", marca="Fiat", motor="1.0", combustivel="Gasolina") # inválido
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ def salario_bonus(bonus):


salario_bonus(500) # 2500
print(salario)
Loading