4
I have the following code segments:
def is_even(num):
if(num % 2 == 0):
return True
return False
1.
lista = range(50)
pares = [i for i in lista if is_even(i)]
# pares = [0, 2, 4, 6, 8...]
2.
lista = range(50)
pares = []
for i in lista:
if is_even(i):
pares.append(i)
# pares = [0, 2, 4, 6, 8...]
In this case, should one use one to the detriment of another? Or is it indifferent? Why?
It depends. On what aspect?
– Leonel Sanches da Silva
Performance/feasibility e.g. In this very one. Which would you choose? Advantages and disadvantages
– Alberto Pimenta