擅长:python、mysql、java
<p>你可以用拉链</p>
<pre><code>>>> enumerated = [range(start, end) for start,end in zip(breaks, breaks[1:])] + [[breaks[-1]]]
>>> enumerated
[[4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14], [15, 16, 17], [18]]
</code></pre>
<p>使用一个自身偏移量为1(<code>zip(breaks, breaks[1:]</code>)的列表压缩是获得所有对的已知“技巧”。这会删除最后一个,所以我手动添加了它。你知道吗</p>