用flatMap算子将[["a b c",["a","b","c"],[4,5,6]],[[7,8,9],["b","c","d"],"s p a r k"]]解除嵌套
时间: 2023-11-17 10:02:13 浏览: 47
删除嵌套树形结构
可以使用flatMap算子将嵌套的列表解除嵌套。flatMap算子会将每个元素映射为一个新的列表,并将所有的新列表合并为一个列表。具体实现如下所示(假设原始列表为list):
```python
result = list.flatMap(lambda x: x)
```
解除嵌套后的结果为:
```python
["a b c", ["a", "b", "c"], [4, 5, 6], [7, 8, 9], ["b", "c", "d"], "s p a r k"]
```
阅读全文