close

How to append a List to Another List in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to append a List to Another List in Python. so without wasting time lets learn about of this.

How to append a List to Another List in Python

  1. append a List to Another List in Python

    to append a List to Another List in Python just use +. By using + operator you can easily extend the list. So lets learn about of this method without wasting time by below example: lst = [2,4,6] lst2 = [3,6,9] lst3 = [4,8,12] finallist = lst + lst2 + lst3 print(finallist) Output : [2, 4, 6, 3, 6, 9, 4, 8, 12]

  2. How to append a List to Another List in Python

    to append a List to Another List in Python just use extend(). By using extend() you can easily extend the list. So lets learn about of this method without wasting time by below example: lst = [2,4,6] lst2 = [3,6,9] lst.extend(lst2) print(lst)
    Output : [2, 4, 6, 3, 6, 9]

  3. python append list to another list

    To append a List to Another List in Python just use extend(). By using extend() you can easily extend the list. So lets learn about of this method without wasting time by below example: lst = [2,4,6] lst2 = [3,6,9] lst.extend(lst2) print(lst)
    Output : [2, 4, 6, 3, 6, 9]

Method 1: Use +

By using + operator you can easily extend the list. So lets learn about of this method without wasting time by below example:

lst = [2,4,6]
lst2 = [3,6,9]
lst3 = [4,8,12]
finallist = lst + lst2 + lst3
print(finallist)

Output :

[2, 4, 6, 3, 6, 9, 4, 8, 12]

Method 2: Use extend()

By using extend() you can easily extend the list. So lets learn about of this method without wasting time by below example:

lst = [2,4,6]
lst2 = [3,6,9]
lst.extend(lst2)
print(lst)

Output :

[2, 4, 6, 3, 6, 9]

Method 3: Use intertool.chain()

By using intertool.chain() you can easily extend the list. So lets learn about of this method without wasting time by below example:

import itertools
lst = [2,4,6]
lst2 = [3,6,9]
lst3 = [4,8,12]
final_list = list(itertools.chain(lst, lst2, lst3))
print(final_list)

Output :

[2, 4, 6, 3, 6, 9, 4, 8, 12]

Method 4: Use for loop

By using for loop you can easily extend the list. So lets learn about of this method without wasting time by below example:

lst = [2,4,6]
lst2 = [3,6,9]
for item in lst2:
    lst.append(item)
print(lst)

Output :

[2, 4, 6, 3, 6, 9]

Method 5: Use insert

By using insert you can easily extend the list. So lets learn about of this method without wasting time by below example:

mylist = ["pizza","burger","dhosa"]
mylist.insert(1, "momos")
print(mylist)

Output :

['pizza', 'momos', 'burger', 'dhosa']

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment