python - Regex Help, por favor -


so have text file comma separated numbers, i'm trying write python me numbers 3 @ time - they're 3d co-ordinates , want analyse them 3 @ time.

the text file of form

x1,y1,z1,x2,y2,...,

and 1 line.

cheers.

yeah, comma separated data evinces need csv simple split here too.

your comma separated string of (x, y, z) coordinates

>>> t = "x1,y1,z1,x2,y2,z2,x3,y3,z3" 

use split :

>>> t1 = t.split(',') >>> t1 ['x1', 'y1', 'z1', 'x2', 'y2', 'z2', 'x3', 'y3', 'z3'] 

then collate / group results 3 elements. need make sure len(t1) multiple of 3s. use assert that.

>>> t2 = [] >>> x in range(len(t1)/3): t2.append(t1[x*3 : x*3+3]) ...  >>> t2 [['x1', 'y1', 'z1'], ['x2', 'y2', 'z2'], ['x3', 'y3', 'z3']] >>>  

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -