Created
March 4, 2020 14:11
-
-
Save RicardoTurco/bb34c45b6d3add9266abc633388b6c77 to your computer and use it in GitHub Desktop.
Python: Iterando utilizando "List Comprehensions"
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
nr = [100, 200, 300] | |
# Acrescentando "10" à cada item, utilizando iteração "normal" | |
for idx, item in enumerate(nr): | |
nr[idx] += 10 | |
# Resultado | |
nr | |
[110, 210, 310] | |
# Restaurando valores "originais" ... | |
nr = [100, 200, 300] | |
# Acrescentando "10" à cada item, utilizando "list comprehensions" | |
nr = [nr[idx]+10 for idx, item in enumerate(nr)] | |
# Resultado | |
nr | |
[110, 210, 310] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment