Skip to content

Instantly share code, notes, and snippets.

@acwoss
Created June 14, 2018 13:32
Show Gist options
  • Save acwoss/097d69852407ca02871d8c7aa4cb26fd to your computer and use it in GitHub Desktop.
Save acwoss/097d69852407ca02871d8c7aa4cb26fd to your computer and use it in GitHub Desktop.
BubblyClearComputergraphics created by acwoss - https://repl.it/@acwoss/BubblyClearComputergraphics
palavra1 = {'palavra': 'sim', 'positivo': 0}
palavra2 = {'palavra': 'não', 'positivo': 0}
palavras = [palavra1, palavra2]
resultado1 = filter(lambda termo: termo['palavra'] == 'sim', palavras)
resultado2 = [termo for termo in palavras if termo['palavra'] == 'sim']
resultado3 = (termo for termo in palavras if termo['palavra'] == 'sim')
print('Utilizando filter:', list(resultado1))
print('Utilizando list comprehension:', resultado2)
print('Utilizando generator comprehension:', list(resultado3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment