擅长:python、mysql、java
<p>可能有一种通过理解来实现这一点的奇特方法,但我认为最简单的选择是迭代地构建列表:</p>
<pre><code>from typing import List, Union
flat_list: List[Union[str, float]] = ['T0000093', 'I717', 'I491', 'I82', 'I345', 'I423', 2469.0, 'T0000166', 'I4', 'I425', 3534.0, 'T0000256', 'I558', 'I325', 'I242', 'I523', 'I568', 'I207', 'I137', 'I15', 'I477', 8467.0]
nested_list: List[List[Union[str, float]]] = []
sub_list: List[Union[str, float]] = []
for item in flat_list:
if isinstance(item, str) and item.startswith("T"):
sub_list = []
nested_list.append(sub_list)
sub_list.append(item)
</code></pre>