【发布时间】:2015-10-19 06:53:53
【问题描述】:
我有一个列表,它可以有不同的大小,但它总是有第一项。我写了这样的理解:
return {
'index': [[i[0][7:], i[1], i[2], i[3]] for i in columns if i[0].startswith("index::")]
}
i[1], i[2], i[3] 部分可能会有所不同。它可以有 0 个或更多大小,我需要将它们指定为列表元素。
类似
return {
'index': [[i[0][7:], *i[1:]] for i in columns if i[0].startswith("index::")]
}
会很棒。
输入:
[['index::test', '1', '2', '3']]
[['index::test', '1', '2', '3', '5']]
[['index::test']]
输出:
[['index', '1', '2', '3']]
[['index', '1', '2', '3', '5']]
[['index']]
【问题讨论】:
-
请发布示例输入和输出!