擅长:python、mysql、java
<p>此解决方案需要第三方模块(<a href="https://iteration-utilities.readthedocs.io/en/latest/generated/Iterable.html" rel="nofollow noreferrer">^{<cd1>}</a>),但应该执行您想要的操作:</p>
<pre><code>>>> from iteration_utilities import Iterable
>>> l = ['hello', 'how', 'are', 'you', 'doing', 'today', 'are', 'you', 'okay']
>>> Iterable(l).successive(2).as_counter()
Counter({('are', 'you'): 2,
('doing', 'today'): 1,
('hello', 'how'): 1,
('how', 'are'): 1,
('today', 'are'): 1,
('you', 'doing'): 1,
('you', 'okay'): 1})
</code></pre>