Skip to content

Instantly share code, notes, and snippets.

@bergpb
Created January 24, 2020 17:37
Show Gist options
  • Select an option

  • Save bergpb/bd87ae2f90125d030523f349f1a49d4c to your computer and use it in GitHub Desktop.

Select an option

Save bergpb/bd87ae2f90125d030523f349f1a49d4c to your computer and use it in GitHub Desktop.
Substituindo o Map por List Comprehension
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