Created
January 24, 2020 17:37
-
-
Save bergpb/bd87ae2f90125d030523f349f1a49d4c to your computer and use it in GitHub Desktop.
Substituindo o Map por List Comprehension
This file contains hidden or 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
| nomes = ["marcos", "rosana", "ricardo", "silvia", "aline"] | |
| # usando map | |
| # def somente_nomes_com_a_letra_r(nome): | |
| # return nome if "r" in nome else "" | |
| # resultado = map(somente_nomes_com_a_letra_r, nomes) | |
| # for r in resultado: | |
| # print(r) | |
| # usando list comprehension | |
| resultado = [nome for nome in nomes if "r" in nome] | |
| for r in resultado: | |
| print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment