python取出list嵌套数据

import itertools
test = [[1, 2], [3, 4], [5, 6]]
print(list(itertools.chain.from_iterable(test)))

#-> [1, 2, 3, 4, 5, 6]

import more_itertools
test = [[1, 2], [1, 2, 3, [4, (5, [6, 7])]], (30, 40), [25, 35]]
print(list(more_itertools.collapse(test)))

#Output=> [-1, -2, 1, 2, 3, 4, 5, 6, 7, 30, 40, 25, 35]

你可能感兴趣的:(python,python)