Created
February 11, 2020 04:46
-
-
Save luizomf/daa038e6b02d8cba125d87a28e66ec8b to your computer and use it in GitHub Desktop.
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
""" | |
Considerando duas listas de inteiros ou floats (lista A e lista B) | |
Some os valores nas listas retornando uma nova lista com os valores somados: | |
Se uma lista for maior que a outra, a soma só vai considerar o tamanho da | |
menor. | |
Exemplo: | |
lista_a = [1, 2, 3, 4, 5, 6, 7] | |
lista_b = [1, 2, 3, 4] | |
=================== resultado | |
lista_soma = [2, 4, 6, 8] | |
""" | |
lista_a = [10, 2, 3, 40, 5, 6, 7] | |
lista_b = [1, 2, 3, 4] | |
lista_soma = [x + y for x, y in zip(lista_a, lista_b)] | |
print(lista_soma) | |
# lista_soma = [] | |
# for i in range(len(lista_b)): | |
# lista_soma.append(lista_a[i] + lista_b[i]) | |
# print(lista_soma) | |
# lista_soma = [] | |
# for i, _ in enumerate(lista_b): | |
# lista_soma.append(lista_a[i] + lista_b[i]) | |
# print(lista_soma) |
Jose-Herbert
commented
Jul 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment