Excellent! You took the time to verify what I was saying without giving proof - and you we right to do so!
The problem is that the last line in the second function is actually building a list.
Here's a better example:
defis_even(x):returnx%2==0@timeitdeffunc1(my_list):""" calling append() in a loop """my_other_list=[]forxinmy_list:ifis_even(x):my_other_list.append(x)func1(list(range(1,9999999)))@timeitdeffunc2(my_list):"""Saving one 'op' by not looking up the is_even
function every time
"""my_other_list=[]func=is_evenforxinmy_list:iffunc(x):my_other_list.append(x)func2(list(range(1,9999999)))@timeitdeffunc3(my_list):"""Using list comprehensions
"""my_other_list=[xforxinmy_listifis_even(x)]func3(list(range(1,9999999)))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Excellent! You took the time to verify what I was saying without giving proof - and you we right to do so!
The problem is that the last line in the second function is actually building a list.
Here's a better example: