I have a string containing around 1 million sets of float/int coords, i.e.:
'5.06433685685, 0.32574574576, 2.3467345584, 1,,,'
They are all in one large string and only the first 3 values are used. The are separated by 3 commas. The code i'm using right now to read through them and assign them to a list is below:
def getValues(s): output =  while s: v1, v2, v3, _, _, _, s = s.split(',', 6) output.append("%s %s %s" % (v1.strip(), v2.strip(), v3.strip())) return output coords = getValues(tempString)
The end results need to be a list of the three floats in each set separated by a space, i.e.:
['5.06433685685 0.32574574576 2.3467345584']
The code I defined above does work for what I want, it just takes much longer than I would like. Does anyone have any opinions or ways I could speed it up? I would like to stay away from external modules/modules i have to download.
Btw I don't think it's my computer slowing it down, 32gb ram and 350mb/s write speed, the program that creates the original string does it in about 20 secs, while my code above gets that same string, extracts the 3 values in around 30mins to an hour.
P.s. Using python 2.6 if it matters
EDIT: Tried replacing the while loop with a for loop as I did some reading and it stated for loops were faster, it might have shaved off an extra minute but still slow, new code:
def getValues(s, ids): output =  for x in range(len(ids)): v1, v2, v3, _, _, _, s = s.split(',', 6) output.append("%s %s %s" % (v1.strip(), v2.strip(), v3.strip())) return output