How to allow list append() method to return the new list

前端 未结 7 1621
春和景丽
春和景丽 2020-12-09 00:31

I want to do something like this:

myList = [10,20,30]
yourList = myList.append (40)

Unfortunately, list append does not return the modified

7条回答
  •  甜味超标
    2020-12-09 01:11

    Try using itertools.chain(myList, [40]). That will return a generator as a sequence, rather than allocating a new list. Essentially, that returns all of the elements from the first iterable until it is exhausted, then proceeds to the next iterable, until all of the iterables are exhausted.

提交回复
热议问题