Python: Append A List at the Start of Another List


If you want to append a list at the start (beginning) of another list in Python then you can do that in many ways, let's take a look at a few.



Example 1: Using extend() function

    nos_list_1 = [2, 4, 0]
    nos_list_2 = [-1, -2, -7] # append this list to list_1
    
    nos_list_2.extend(nos_list_1)
    print(nos_list_2)
    Output:
    [-1, -2, -7, 2, 4, 0]


Example 2: Using + Operator

    nos_list_1 = [2, 4, 0]
    nos_list_2 = [-1, -2, -7]
    
    appended_list = nos_list_2 + nos_list_1
    print(appended_list)
    Output:
    [-1, -2, -7, 2, 4, 0]

Example 3: Using Unpacking

    nos_list_1 = [2, 4, 0]
    nos_list_2 = [-1, -2, -7]
    
    appended_list = [*nos_list_2, *nos_list_1]
    print(appended_list)
Examples - Appending List at the start of another list

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap