Python List reverse()

This tutorial shows you everything you need to know to help you master the essential reverse() method of the most fundamental container data type in the Python programming language. Definition and Usage: The list.reverse() reverses the order of the elements in the list. If you want to create a new list with reversed elements, use … Read more

Python List pop()

This tutorial shows you everything you need to know to help you master the essential pop() method of the most fundamental container data type in the Python programming language. Definition and Usage: The list.pop() method removes and returns the last element from an existing list. The list.pop(index) method with the optional argument index removes and … Read more

Python List copy()

Surprisingly, even advanced Python coders don’t know the details of the copy() method of Python lists. Time to change that! Definition and Usage: The list.copy() method copies all list elements into a new list. The new list is the return value of the method. It’s a shallow copy—you copy only the object references to the … Read more

Python List clear()

Surprisingly, even advanced Python coders don’t know about the clear() method of Python lists. Time to change that! Definition and Usage: The list.clear() method removes all elements from an existing list. The list becomes empty again. Here’s a short example: In the first line, you create the list lst consisting of five integers. You then … Read more

Python List remove()

This tutorial shows you everything you need to know to help you master the essential remove() method of the most fundamental container data type in the Python programming language. Definition and Usage: The list.remove(element) method removes the first occurrence of the element from an existing list. It does not, however, remove all occurrences of the … Read more

Python List extend() Method

How can you not one but multiple elements to a given list? Use the extend() method in Python. This tutorial shows you everything you need to know to help you master an essential method of the most fundamental container data type in the Python programming language. Definition and Usage The list.extend(iter) method adds all elements … Read more

How to Concatenate Lists in Python? [Interactive Guide]

So you have two or more lists and you want to glue them together. This is called list concatenation. How can you do that? These are six ways of concatenating lists: List concatenation operator + List append() method List extend() method Asterisk operator * Itertools.chain() List comprehension Output: What’s the best way to concatenate two … Read more