Here is how to merge two lists in Python.


# Create two sample lists
x = [1, 2, 3]
y = [10, 20, 30] 
# Merge the lists
merged = x + y 
# Print out the merged list
print(list(merged)) 

Output

[1, 2, 3, 10, 20, 30]


Explanation

Note that the Python code above merges the lists linearly. If instead you want to create pairs of items from each list, you might want to use the Python zip function:

# Create two sample lists
x = [1, 2, 3]
y = [10, 20, 30]

# Use zip to get item pairs
merged = zip(x, y)

# Print out the merged list
print(list(merged))


Related HowTos
Do dictionary comprehension
Do list comprehension
Create a virtual environment
Create a new file
Extract items from two different lists into one list
Check if a text file is empty
Randomly select an item from a list
Generate a random integer
Break a while loop
Create a pandas DataFrame from a dictionary
Create a pandas DataFrame from a list
Get the last item of a list
Delete a column from a pandas dataframe
Access a column of a pandas dataframe
Create a class
Make a webpage request
Get the first two characters of a string
<django.db.models.fields.CharField>
Recommended Course

Learn Flask development and learn to build cool apps with our premium Python course on Udemy.


Mailing List

We will keep you Python-motivated if you subscribe below.