2
如果我有兩個字符串的元組列表的列表的列表。我想壓平到元組的非嵌套列表,我可以這樣做:有沒有辦法避免這麼多的鏈表(chain(* list_of_list))?
>>> from itertools import chain
>>> lst_of_lst_of_lst_of_tuples = [ [[('ab', 'cd'), ('ef', 'gh')], [('ij', 'kl'), ('mn', 'op')]], [[('qr', 'st'), ('uv', 'w')], [('x', 'y'), ('z', 'foobar')]] ]
>>> lllt = lst_of_lst_of_lst_of_tuples
>>> list(chain(*list(chain(*lllt))))
[('ab', 'cd'), ('ef', 'gh'), ('ij', 'kl'), ('mn', 'op'), ('qr', 'st'), ('uv', 'w'), ('x', 'y'), ('z', 'foobar')]
但有拆包元組的非嵌套列表withou嵌套list(chain(*lst_of_lst))
的另一種方式?