我在列表中有一系列数字,我正在寻找一个优雅的解决方案,最好是列表理解,以获得单个序列(包括单个值).我已经解决了这个小问题,但它并不是非常pythonic.
以下列表定义了输入序列:
input = [1, 2, 3, 4, 8, 10, 11, 12, 17]
Run Code Online (Sandbox Code Playgroud)
期望的输出应该是:
output = [
[1, 2, 3, 4],
[8],
[10, 11, 12],
[17],
]
Run Code Online (Sandbox Code Playgroud)