【发布时间】:2021-08-10 14:21:24
【问题描述】:
我想根据该列表中的元素将以下列表拆分为子列表。
array=['first','sentence','step','second','sentence']
for i in array:
if i!='step':
newlist1.append(i)
else:
(stop appending in newlist1 and start appending in say newlist2)
newlist1 和 newlist2 不能预先声明。由于数组中的元素数量可能会有所不同。所以我需要根据要求找到一种动态声明列表的方式。
【问题讨论】:
-
步骤是否应该包含在第二个列表中?
-
没有步骤用作分隔元素。最好将其删除
标签: python python-3.x list append