from itertools import groupby
data = [123, '', '456', '', '789']
# 其中data是我们需要分割的列表,x==''是我们以那个元素分割
result = [list(g) for k, g in groupby(data, lambda x:x=='') if not k]
print(result)

运行结果:[[123], ['456'], ['789']]
 
 
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
猜你喜欢
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-02-05
相关资源
相似解决方案