list的list合并成一个list
时间: 2023-09-13 13:08:03 浏览: 121
Python将多个list合并为1个list的方法
可以使用`extend`方法来将多个列表合并成一个列表。具体操作如下:
```python
list_of_lists = [[1, 2], [3, 4], [5, 6]]
merged_list = []
for lst in list_of_lists:
merged_list.extend(lst)
print(merged_list)
```
输出:
```
[1, 2, 3, 4, 5, 6]
```
或者使用列表推导式:
```python
list_of_lists = [[1, 2], [3, 4], [5, 6]]
merged_list = [item for sublist in list_of_lists for item in sublist]
print(merged_list)
```
输出:
```
[1, 2, 3, 4, 5, 6]
```
阅读全文