Prepend Elements to Lists in Python Last Updated : 17 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In Python, prepending means adding elements to the beginning of a list. We can think of it as putting something at the front of a queue. In this article, we will explore various methods to prepend elements to lists in Python. The insert() method to add an element at a specific position in a list. To add an element at the beginning, we can specify position 0. Python a = [2, 3, 4] # Adds 1 at the beginning of the list a.insert(0, 1) print(a) Output[1, 2, 3, 4] Other methods that we can use to prepend elements to a list are:Table of ContentUsing + OperatorUsing collections.dequeUsing + OperatorAnother simple method is to use the + operator to concatenate lists. We can create a new list with the element to be prepended and then join it with the original list. Python a = [2, 3, 4] b = [1] # Adds 1 at the beginning by joining two lists a = b + a print(a) Output[1, 2, 3, 4] Using collections.dequeThis is one of the most efficient ways to prepend elements if we are working with lists that change frequently. The deque (double-ended queue) is optimized for appending and prepending elements quickly. Python from collections import deque a = deque([2, 3, 4]) # Adds 1 at the beginning of the deque a.appendleft(1) print(a) Outputdeque([1, 2, 3, 4]) Comment More infoAdvertise with us Next Article Convert Tuple to List in Python S subramanyasmgm Follow Improve Article Tags : Python python-list Practice Tags : pythonpython-list Similar Reads How to add Elements to a List in Python In Python, lists are dynamic which means that they allow further adding elements unlike many other languages. In this article, we are going to explore different methods to add elements in a list. For example, let's add an element in the list using append() method:Pythona = [1, 2, 3] a.append(4) prin 2 min read Print lists in Python Printing a list in Python is a common task when we need to visualize the items in the list. There are several methods to achieve this and each is suitable for different situations. In this article we explore these methods.The simplest way of printing a list is directly with the print() function:Pyth 3 min read Map vs List comprehension - Python List comprehension and map() both transform iterables but differ in syntax and performance. List comprehension is concise as the logic is applied in one line while map() applies a function to each item and returns an iterator and offering better memory efficiency for large datasets.List comprehensio 2 min read Convert Tuple to List in Python In Python, tuples and lists are commonly used data structures, but they have different properties:Tuples are immutable: their elements cannot be changed after creation.Lists are mutable: they support adding, removing, or changing elements.Sometimes, you may need to convert a tuple to a list for furt 2 min read range() to a list in Python In Python, the range() function is used to generate a sequence of numbers. However, it produces a range object, which is an iterable but not a list. If we need to manipulate or access the numbers as a list, we must explicitly convert the range object into a list. For example, given range(1, 5), we m 2 min read Extending a list in Python In Python, a list is one of the most widely used data structures for storing multiple items in a single variable. Often, we need to extend a list by adding one or more elements, either from another list or other iterable objects. Python provides several ways to achieve this. In this article, we will 2 min read Like