擅长:python、mysql、java
<p>每个事务都以“T”开头。可以使用此选项将列表拆分为嵌套列表。代码如下所示:</p>
<pre><code>L=['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=[]
for x in L:
if(len(List)==0):
List.append(x)
elif(type(x)==str and x[0]=='T'):
nested_list.append(List)
List=[]
List.append(x)
else:
List.append(x)
if(len(List)!=0):
nested_list.append(List)
print(nested_list)
</code></pre>