Take the content of a list and append it to another list

后端 未结 7 1752
死守一世寂寞
死守一世寂寞 2020-12-07 08:55

I am trying to understand if it makes sense to take the content of a list and append it to another list.

I have the first list created through a loop function, that

7条回答
  •  时光说笑
    2020-12-07 09:11

    Take a look at itertools.chain for a fast way to treat many small lists as a single big list (or at least as a single big iterable) without copying the smaller lists:

    >>> import itertools
    >>> p = ['a', 'b', 'c']
    >>> q = ['d', 'e', 'f']
    >>> r = ['g', 'h', 'i']
    >>> for x in itertools.chain(p, q, r):
            print x.upper()
    

提交回复
热议问题