python - Create list from two tuples of tuples -


i have 2 tuples of tuples:

dcf3t=((((1.90683376789093, -44705.1875), (1.90689635276794, -44706.76171875)),),) du1t=((((0.0, 0.00244894321076572), (0.00249999994412065, 0.00782267469912767)),),) 

i need create list value of second column of each tuple:

dfd=[] dfd.append([x[1] x in du1t, y[1] y in dcf3t]) 

example:

dfd=[[0.00244894321076572,-44705.1875],[0.00782267469912767,-44706.76171875]] 

but gives me error: name 'y' not defined

p.s.: both tuples created lists of lists of tuples.

edit: avoid ,),) @ end of tuples please consider:

dcf3t=[[((1.90683376789093, -44705.1875), (1.90689635276794, -44706.76171875))]] du1t=[[((0.0, 0.00244894321076572), (0.00249999994412065, 0.00782267469912767))]] 

solution:

    dfd=[]     in range(0, len(du1t[0][0])):         dfd.append([du1[0][0][i][1],dcf3[0][0][i][1]]) 

i believe you're looking for

dfd=[[x[1],y[1]] x,y in zip(du1t[0], dcf3t[0])] 

in general, should try avoid appending things as possible; typically slows down because can require copying entire list new location in memory. in example, append statement trivial, wouldn't cost much, it's unnecessary.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -