Last active
November 4, 2018 22:15
-
-
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
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_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