Python program to append entire list to another list

Write a python program to append entire list to another list.

There are sevral methods to append entire list to another list. Python have some function and operator to do this like extend(), chain() etc.

Method-01

list01 = [10,20,30,40,50]
list02 = [60,70,80,90,100]
list03 = [110,120,130,140,150]

list04 = list01+list02+list03
print(list04)

Output:

[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]

 

Method-02

list01 = [10,20,30,40,50]
list02 = [60,70,80,90,100]
list03 = [110,120,130,140,150]

list02.extend(list03)
list01.extend(list02)
print(list01)

Output:

[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]

 

Method-03

import itertools

list01 = [10,20,30,40,50]
list02 = [60,70,80,90,100]
list03 = [110,120,130,140,150]

list04 = list(itertools.chain(list01,list02,list03))
print(list04)

Output:

[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]

Leave a comment