Last active
October 28, 2017 20:52
-
-
Save wuerges/d975738888db33eacfffd48417add262 to your computer and use it in GitHub Desktop.
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
size = 100000 | |
def f1(): | |
lista = list(range(size)) | |
eliminados = [] | |
for i in lista: | |
if i%2 != 0: | |
eliminados.append(lista.pop(lista.index(i))) | |
return lista | |
def f2(): | |
lista = list(range(size)) | |
eliminados = [] | |
remanescentes = [] | |
for i in lista: | |
if i%2 != 0: | |
eliminados.append(i) | |
else: | |
remanescentes.append(i) | |
lista[:] = remanescentes | |
return lista | |
import timeit | |
print("versao original:", timeit.timeit(f1, number=1)) | |
print("versao com nova lista:", timeit.timeit(f2, number=1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment