Oct-06-2020, 11:39 PM
You should use a list comprehension to make both lists. The A list is pretty short and speeding that up won't make much difference. The B list is roughly 16 times longer for your test case and anything you can do to speed that up will make a big difference,
A = [i for i in range(?, ?, ?)]
B = [i for i in range(?, ?) if ?]
A list comprehension is so much faster than using .append() mostly because you avoid the overhead of calling a function and cleaning up afterward. In many cases it takes more time to call a function than it takes for the function to execute.
A = [i for i in range(?, ?, ?)]
B = [i for i in range(?, ?) if ?]
A list comprehension is so much faster than using .append() mostly because you avoid the overhead of calling a function and cleaning up afterward. In many cases it takes more time to call a function than it takes for the function to execute.