How to prepend to a list in Python

Prepending to a list adds an element to the beginning of the list. For instance, prepending 1 to [2, 3] results in [1, 2, 3].

Solution for How to prepend to a list in Python : You can use list.insert() to prepend to a list Call a_list.insert(index, element) on a_list with index set to 0 to add an element to the beginning of a_list.


how-to-prepend-to-a-list-in-python