How can I get the concatenation of two lists in Python without modifying either one?

Ryan C. Thompson picture Ryan C. Thompson · Dec 3, 2010 · Viewed 892.5k times · Source

In Python, the only way I can find to concatenate two lists is list.extend, which modifies the first list. Is there any concatenation function that returns its result without modifying its arguments?

Answer

NPE picture NPE · Dec 3, 2010

Yes: list1 + list2. This gives a new list that is the concatenation of list1 and list2.