发布于 1年前
Python 如何将嵌套列表合并为一个列表
main_list = [[0, 1, 2], [11, 12, 13], [52, 53, 54]]
result = [item for sublist in main_list for item in sublist]
print(result)
>
[0, 1, 2, 11, 12, 13, 52, 53, 54]
main_list = [[0, 1, 2], [11, 12, 13], [52, 53, 54]]
result = [item for sublist in main_list for item in sublist]
print(result)
>
[0, 1, 2, 11, 12, 13, 52, 53, 54]