擅长:python、mysql、java
<p>使用<a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="noreferrer">^{<cd1>}</a>,可以按<code>str.isalpha</code>分组,有条件地连接字符串,然后链接结果:</p>
<pre><code>from itertools import chain, groupby
L = ['New', 'Jersey', '1', '0', '1', '999']
grouper = groupby(L, key=str.isalpha)
joins = [[' '.join(v)] if alpha_flag else list(v) for alpha_flag, v in grouper]
res = list(chain.from_iterable(joins))
print(res)
['New Jersey', '1', '0', '1', '999']
</code></pre>