Python Forum
Time limit exceed problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time limit exceed problem
#11
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help on Time Series problem Kishore_Bill 1 4,849 Feb-27-2020, 09:07 AM
Last Post: Kishore_Bill

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020