python list columns split
<p>Could anyone help me please? It is complicated question but i will try explain it. I need interpolate two values Depths(Z) to Speed(v) for all data </p>

<pre><code>x= [55,55,55,,44,44,44,,33,33,33,] (coordinates)
z =[10,5,0,10,7,0,10,9,0]  (depths)
v= [20,21,22=,23,24,25,26,27,28] (speed)
</code></pre>

<p>And result </p>

<pre><code>DEPTHS   SPEED(55)        SPEED(44)              SPEED(33)     
10       20              23                      26
6        21.5(interp)    24.5(interp)            27.5 (interp)
0        22              25                      28
</code></pre>

<p>What I did:</p>

<pre><code>import numpy as np
    X_list=[55,55,55,44,44,44,33,33,33] 
    Z_list=[10,5,0,10,7,0 10,9,0]
    V_list=[20,21,22,23,24,25,26,27,28]
    x = np.linspace(min(Z_list),max(Z_list),num = 3) #(Find min and max values in  all list, and put step
    d=np.interp(x, Z_list, V_list) # interpolation for interesting depths
    zipped = list(zip(x,d))
    print (*zipped, sep="\n")
</code></pre>

<p>And actually I got  information from first cordinate</p>

<pre><code> DEPTHS    SPEED(55)    SPEED (44)      SPEED(33)    

    (10     20)          ?             ?
    (6      21.5)        ?             ?
    (0      22)          ?             ?
</code></pre>

<p>But I dont't  know how to get other values from another cordinates.
I haven't got any idea how link coordinates to speeds and depths and put it to columns. </p>

<p>One possibility is to create a dictionary that maps each X coord to the list of tuples with that X coord:</p>

<pre><code>&gt;&gt;&gt; tupus = [ (1,0,1), (1,13,4), (2,11,2), (2,14,5) ]
&gt;&gt;&gt; from collections import defaultdict
&gt;&gt;&gt; tupudict = defaultdict( lambda: [] ) # default val for a key is empty list
&gt;&gt;&gt; for tupu in tupus: tupudict[tupu[0]].append(tupu)
...
&gt;&gt;&gt; tupudict[1]
[(1, 0, 1), (1, 13, 4)]
&gt;&gt;&gt; tupudict[2]
[(2, 11, 2), (2, 14, 5)]
</code></pre>

<p>Then you process the dict key by key, or dump the values into a list of lists of tuples, or whatever.</p>

<p>Edited to add an answer to your comment about just splitting a list:</p>

<pre><code>&gt;&gt;&gt; from collections import defaultdict
&gt;&gt;&gt; mylist = [11,11,11,11,12,12,15,15,15,15,15,15,20,20,20]
&gt;&gt;&gt; uniquedict = defaultdict( lambda: [] )
&gt;&gt;&gt; for n in mylist: uniquedict[n].append(n)
...
&gt;&gt;&gt; uniquedict
defaultdict(&lt;function &lt;lambda&gt; at 0x00000000033092E8&gt;, {20: [20, 20, 20], 11: [11, 11, 11, 11], 12: [12, 12], 15: [15, 15, 15, 15, 15, 15]})
&gt;&gt;&gt; uniquedict[11]
[11, 11, 11, 11]
</code></pre>

<p>Note that, for every n in your input list, uniquedict[n] is now a list of all the n's from your input list.</p>

python list listview interpolation