Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Most recent version:</h2> <pre><code>def zipij7(m=mem, ms=mems): cpy = sorted(ms + [m]) loc = cpy.index(m) return zip(ms[:(loc)], repeat(m)) + zip(repeat(m), ms[(loc):]) </code></pre> <p>Benches slightly faster for me than truppo's, slower by 30% than Michal's. (Looking into that now)</p> <hr> <p>I may have found my answer (for now). It seems I forgot about making a list comp version for `zipij()``:</p> <pre><code>def zipij1(m=mem, ms=mems, f=ij): return [f(i, m) for i in ms] </code></pre> <p>It still relies on my silly <code>ij()</code> helper function, so it doesn't win the award for brevity, certainly, but timings have improved:</p> <pre><code># 10000 1.27s # 50000 6.74s </code></pre> <p>So it is now my current "winner", and also does not need to generate more than one list, or use a lot of function calls, other than the <code>ij()</code> helper, so I believe it would also be the most efficient.</p> <p>However, I think this could still be improved... I think that making N <code>ij()</code> function calls (where N is the length of the resultant list) is not needed:</p> <ul> <li>Find at what index <code>mem</code> would fit into <code>mems</code> when ordered</li> <li>Split mems at that index into two parts</li> <li>Do <code>zip(part1, repeat(mem))</code></li> <li>Add <code>zip(repeat(mem), part2)</code> to it</li> </ul> <p>It'd basically be an improvement on <code>zipij4()</code>, and this avoids N extra function calls, but I am not sure of the speed/memory benefits over the cost of brevity. I will maybe add that version to this answer if I figure it out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload