# Create lists from data list

 

'''

0  (0  ,0  ,0  )

5  (5  ,0  ,0  )

10 (10 ,0  ,0  )

15 (15 ,5  ,0  )

20 (20 ,10 ,0  )

25 (25 ,15 ,0  )

30 (30 ,20 ,5  )

35 (30 ,25 ,10 )

40 (30 ,30 ,15 )

45 (30 ,30 ,20 )

50 (30 ,30 ,25 )

'''

 

## CODE COMMON TO SOLUTIONS

import re

 

fn = r'H:\TEMP\temsys\cameratrack.txt'

patt = r'\d+'

varList = ['frame', 'coordx', 'coordy', 'coordz']

 

## SOLUTION 1 #############################################

fList = open(fn).readlines()

data = [re.findall(patt,item) for item in fList]

 

data1 = [[], [], [], []]

 

for i in range(4):

    for item in data:

        data1[i].append(float(item[i]))

 

for lst in data1:

    print lst

 

for i, v in enumerate(varList):

    exec '%s = %s' % (v, data1[i])   

 

## SOLUTION 2 #############################################

print

 

fList = open(fn).readlines()

data = [re.findall(patt,item) for item in fList]

 

data2 = [[float(item[i]) for i in range(len(varList)) for item in data][j:j+len(data)] \

         for j in range(0,len(data)*len(varList),len(data))]

 

for lst in data2:

    print lst

 

for i, v in enumerate(varList):

    exec '%s = %s' % (v, data2[i])   

 

## SOLUTION 3 ############################################

print

 

data = zip(*[re.findall(patt,item) for item in open(fn).readlines()])

 

for i, v in enumerate(varList):

    exec '%s = %s' % (v, [float(i) for i in data[i]])

 

print frame

print coordx

print coordy

print coordz

 

## SOLUTION 4 ############################################

print

 

import re

 

fn = r'H:\TEMP\temsys\cameratrack.txt'

patt = r'\d+'

varList = ['frame', 'coordx', 'coordy', 'coordz']

 

fList = open(fn).readlines()

data = [re.findall(patt,item) for item in fList]

 

dataDict = dict(zip(['frame', 'coordx', 'coordy', 'coordz'], [[],[],[],[]]))

 

for i, key in enumerate(dataDict):

     for item in data:

          dataDict[key].append(float(item[i]))

 

for key in dataDict:

    print '%s = %s' % (key, dataDict[key])

 

## SOLUTION 5 ############################################

print

 

import re

 

fn = r'H:\TEMP\temsys\cameratrack.txt'

patt = r'\d+'

varList = ['frame', 'coordx', 'coordy', 'coordz']

 

fList = open(fn).readlines()

dataDict = dict(zip(varList,zip(*[re.findall(patt,item) for item in fList])))

 

for key in dataDict:

    print '%s = %s' % (key, dataDict[key])   

 

## SOLUTION 6 ############################################

print

 

import re

 

fn = r'H:\TEMP\temsys\cameratrack.txt'

patt = r'\d+'

varList = ['frame', 'coordx', 'coordy', 'coordz']

 

data = zip(*[re.findall(patt,item) for item in open(fn).readlines()])

 

dataDict = {}

 

for i, key in enumerate(varList):

    dataDict[key] = [float(i) for i in data[i]]

 

for key in dataDict:

    print '%s = %s' % (key, dataDict[key])   

 

'''

frame = [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0]

coordz = [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0, 30.0, 30.0]

coordy = [0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0]

coordx = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0]

'''

 

'''

>>> [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0]

[0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0, 30.0, 30.0]

[0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0]

[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0]

 

[0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0]

[0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0, 30.0, 30.0]

[0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0]

[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0]

>>>

'''

 

'''

>>> varList = ['frame', 'coordx', 'coordy', 'coordz']

>>> for i, v in enumerate(varList):

... exec '%s = %s' % (v, data2[i])

...

>>> frame

[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]

>>> coordx

[0, 5, 10, 15, 20, 25, 30, 30, 30, 30, 30]

>>> coordy

[0, 0, 0, 5, 10, 15, 20, 25, 30, 30, 30]

>>> coordz

[0, 0, 0, 0, 0, 0, 5, 10, 15, 20, 25]

>>>

'''