Skip to content

Instantly share code, notes, and snippets.

@antunesleo
Last active November 4, 2018 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antunesleo/6caa7c5e1b86405fbbacd0facb7e0f8d to your computer and use it in GitHub Desktop.
Save antunesleo/6caa7c5e1b86405fbbacd0facb7e0f8d to your computer and use it in GitHub Desktop.
Como verificar se um item faz parte de uma lista de maneira mais performatica em python
nomes_list = ["Leonardo", "Jao", "Ana"] # Mais devagar, usando list
if "Pythonson" in nomes_list:
print("Pythonson ta na lista de nomes")
else:
print("Pythonson nao ta na lista de nomes")
nomes_set = {"Leonardo", "João", "Ana"} # Mais rápido, usando set
if "Pythonson" in nomes_set:
print("Pythonson ta na lista de nomes")
else:
print("Pythonson nao ta na lista de nomes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment