【发布时间】:2021-01-30 22:58:48
【问题描述】:
如何根据特定值拆分整数列表?例如,请参见以下示例:
inp = [1, 3, 4, 5, -999, 0, 0, 1, 3, 5, -999, 85, 82, 84]
outs = magic_function(inp)
>> [[1,3,4,5], [0,0,1,3,5], [85,82,84]] # expected output is like this
输出将是一个基于 -999 拆分的列表列表。到目前为止,我使用 for-loop 处理它或将其转换为字符串,然后使用 str.split('-999') 但我想知道是否有任何优雅(更有效)的方法来做到这一点?
【问题讨论】:
-
在上面的链接中,this particular answer 有一个解决方案来做到这一点
标签: python python-3.x