Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slow Python Code
#1
Hi all,

I have two lists that I want to check if the values in the list called data are equal to the values in the list called data2. If they are then append 3 values next to the value found in data2 i.e. index +1,+2 and +3 in a new list.

The length of data2 is 2364004 and data is 5131.

I have tried the following code which works but takes a long time to run.

data3.extend([data2[index+1],data2[index+2],data2[index+3]]) for i in data for index, j in enumerate(data2) if i==j
Is there a more efficient/faster way of doing this? Maybe using a numpy array function if need be or something else?

I can post the raw data if that helps

Thanks!
Reply


Messages In This Thread
Slow Python Code - by Jay123 - Sep-05-2019, 02:43 PM
RE: Slow Python Code - by stullis - Sep-05-2019, 10:27 PM
RE: Slow Python Code - by scidam - Sep-06-2019, 12:23 AM
RE: Slow Python Code - by Jay123 - Sep-09-2019, 08:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My python code is running very slow on millions of records shantanu97 7 2,592 Dec-28-2021, 11:02 AM
Last Post: Larz60+
  Optmized way to rewrite this very slow code liva28 0 1,501 Jul-18-2021, 12:16 PM
Last Post: liva28
  Python file to slow, how peed up ? Leon 4 3,082 Jan-05-2019, 09:40 AM
Last Post: Gribouillis
  simple code is way too slow JAREDZ 7 8,109 Nov-11-2018, 12:03 PM
Last Post: Larz60+
  Python 2.7 Addition to dict is too slow VolanD 6 4,056 May-04-2018, 09:24 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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