Search code examples
pythonbuilder

Builder pattern for python lists


I just spent some time confused why the following were returning None:

newList =  myList.extend(anotherList)

So it appears the extend is an in-place mutator only. Is that all we're left with here .. i.e. is there any builder pattern for python lists ?


Solution

  • As @CoryKramer said: just use + ..

    This would seem very (very..) obvious except that I had tried

    list1 + element1

    for another code snippet and that does not work. There is only

    list1 + *list2*