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

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -