How to append multiple values to a list in Python
Categories:
Efficiently Append Multiple Values to a Python List

Learn various Python techniques to add multiple elements to a list, from simple concatenation to in-place modifications and performance considerations.
Python lists are versatile and fundamental data structures. Often, you'll find yourself needing to add more than one item to an existing list. While appending a single item is straightforward with list.append()
, handling multiple items requires different approaches. This article explores several effective methods to append multiple values to a Python list, discussing their use cases, performance implications, and best practices.
Method 1: Using extend()
for In-Place Appending
The list.extend()
method is the most idiomatic and efficient way to add all items from an iterable (like another list, tuple, or string) to the end of the current list. It modifies the list in-place, meaning it doesn't create a new list object, which can be beneficial for performance and memory usage, especially with large lists.
my_list = [1, 2, 3]
new_elements = [4, 5, 6]
my_list.extend(new_elements)
print(my_list)
# Output: [1, 2, 3, 4, 5, 6]
another_list = ['a', 'b']
my_list.extend(('c', 'd')) # extend also works with tuples
print(my_list)
# Output: [1, 2, 3, 4, 5, 6, 'a', 'b', 'c', 'd']
Using extend()
to add multiple elements from a list or tuple.
extend()
modifies the list in-place and returns None
. If you need a new list with the combined elements, consider using list concatenation with the +
operator.Method 2: List Concatenation with the +
Operator
The +
operator allows you to concatenate two or more lists, creating a new list that contains all elements from the original lists. This method is straightforward and readable, but it's important to understand that it generates a new list object. For very large lists or frequent concatenations in a loop, this can lead to higher memory consumption and slower performance compared to extend()
.
list1 = [10, 20]
list2 = [30, 40]
list3 = [50]
combined_list = list1 + list2 + list3
print(combined_list)
# Output: [10, 20, 30, 40, 50]
# Original lists remain unchanged
print(list1)
# Output: [10, 20]
Concatenating multiple lists using the +
operator.
flowchart TD A[Original List] --> B{Add New Elements?} B -- Yes --> C{In-place or New List?} C -- In-place --> D[Use `extend()`] D --> E[List Modified] C -- New List --> F[Use `+` Operator] F --> G[New List Created] B -- No --> H[No Change]
Decision flow for appending multiple values to a list.
Method 3: Using List Comprehension or map()
for Transformed Appending
Sometimes, you might need to append multiple values that are derived or transformed from another iterable. List comprehensions or the map()
function combined with extend()
or +
can be very powerful for these scenarios. While not directly 'appending multiple values' in the simplest sense, they allow you to generate multiple values and then add them to a list.
original_list = [1, 2, 3]
# Using list comprehension to generate and extend
squared_numbers = [x * x for x in [4, 5, 6]]
original_list.extend(squared_numbers)
print(original_list)
# Output: [1, 2, 3, 16, 25, 36]
# Using map() and extend()
def double(n):
return n * 2
more_numbers = [7, 8]
doubled_more_numbers = list(map(double, more_numbers))
original_list.extend(doubled_more_numbers)
print(original_list)
# Output: [1, 2, 3, 16, 25, 36, 14, 16]
Appending transformed values using list comprehension and map()
.
+
(e.g., my_list = my_list + new_items
). This creates a new list in each iteration, leading to O(N^2)
performance for N
appends, which is highly inefficient. Use extend()
or append()
for better performance in loops.Performance Considerations
The choice between extend()
and +
often comes down to performance, especially when dealing with large datasets or performance-critical applications. extend()
is generally more efficient because it modifies the list in-place, avoiding the overhead of creating new list objects. The +
operator, while convenient, involves creating a new list and copying all elements from the original lists, which can be slower and consume more memory.

Comparison of extend()
vs. +
operator for appending multiple values.
For scenarios where you need to add elements one by one, append()
is the correct choice. When adding multiple elements from an iterable, extend()
is usually preferred for its efficiency. The +
operator is best suited for creating a new combined list when the original lists should remain untouched or when the number of concatenations is small.