Wednesday, 15 January 2014

python - Slicing Data From a Dictionary -


I have a code that will properly return the list of xyz coordinates (or list of xyz coordinates) my problem is that I want to use different numbers directly from those lists, but I can only access the entire list at a time. My code: import such as np a = [([2, -2, 0.2 9]), ([-2, 0, 1.9]), ([2, 1, 2.35] ]), ([2, -3, 2.9 6])] B = [0,2,3] Merijip = list (zip (a, b)) = = {myZip in x}: result.setdefault (x) [1], []) .andand (x [0]) xyz = [] for each_index in B: xyz.append (Results [every_index]) print (xyz) xyz.clear ()

will return:

  [[[2, -2, 0.2 9]]] [[-2, 0, 1. 9]]] [[[2, 1] , 2.35]]]   

Now I want to divide it into x and y so x = [2, -2,2] and y = [- 2,0,1]. I have tried to piece it straight, but I get an error about the pieces and not the whole, not the tuples. I also tried to change the numpy using np.hsplit. How can this be achieved? Thanks guys (or girls).

edit

I know that in these cases it will only be printed at a time, but in my real world example, there are such times Where it will return ([x, y, x], [x, y, z]).

Use a list comprehension:

  gt; & Gt; X = [result [i] [0] [0] i for b]> gt; & Gt; & Gt; Y = [result [i] [0] [1] i for b]> gt; & Gt; & Gt; Print x, y [2, -2, 2] [-2, 0, 1]    

No comments:

Post a Comment