Python

Python: Checking If a List Contains an Element (3 Approaches)

Updated: June 16, 2023 By: Khue

This concise, example-based article will walk you through 3 different ways to check whether a Python list contains an element. There’s no time to waste; let’s get started!…

Python: How to Compare 2 Lists (3 Approaches)

Updated: June 16, 2023 By: Khue

Comparing 2 lists in Python refers to determining whether the lists are equal or have any differences. Equality between lists is typically defined as having the same elements…

Python: How to Swap 2 Elements in a List (2 Approaches)

Updated: June 16, 2023 By: Khue

When writing code in Python, there might be cases where you need to exchange the position of 2 elements in a list to achieve a desired outcome or…

Python: 2 Ways to Find Common Elements in 2 Lists

Updated: June 16, 2023 By: Khue

When working with Python, there might be cases where you want to find all mutual elements in 2 lists to identify shared values, determine overlapping elements, or measure…

Python reduce() function: Tutorial & examples

Updated: June 16, 2023 By: Khue

Overview The reduce() function in Python is part of the functools module and is used to perform a specified function on a sequence of elements, reducing it to…

Python: 2 Ways to Check if a Date String is Valid

Updated: June 15, 2023 By: Khue

Overview In general (and in the context of this article), a valid date string can be considered a date string in the ISO 8601 format. The ISO 8601…

Filtering Lists in Python (4 Examples)

Updated: June 13, 2023 By: Wolf

Ways to Filter a List in Python In Python, both the filter() function and list comprehension can be used to filter a list. The choice between them depends…

List Comprehension in Python: Tutorial & Examples

Updated: June 13, 2023 By: Khue

Overview Python brings to the table an awesome feature that not many popular programming languages have (including JavaScript): list comprehension. It allows you to create new lists by…

Python: How to Remove Duplicates from a List (with Examples)

Updated: June 13, 2023 By: Khue

Removing duplicates from a list in Python means creating a new list that contains only the unique elements of the original list. This can be useful for eliminating…

Cloning a List in Python (Deep Copy & Shallow Copy)

Updated: June 13, 2023 By: Khue

What is list cloning? In Python, “cloning a list” means creating a new list object that has the same elements as an existing list. The cloned list is…

1 51 52 53 54 55 64