How to Concatenate Two Lists of Different Sizes in Python?

Estimated read time 1 min read

To concatenate two lists of different sizes in Python, you can use the extend method or the + operator. Here are examples of both approaches:

  1. Using the extend method:
list1 = [1, 2, 3]
list2 = [4, 5, 6, 7]

  1. Using the + operator:
list1 = [1, 2, 3]
list2 = [4, 5, 6, 7]

concatenated_list = list1 + list2

Both approaches will produce the same result. The extend method modifies the original list1 in place, whereas the + operator creates a new list and assigns it to the concatenated_list variable. You can choose the approach that suits your needs.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply