Blog

python tutorials and learn python

Created with Sketch.

Python Set Intersection

Python Set Intersection Summary: in this tutorial, you’ll learn about the Python set intersection and how to use it to intersect two or more sets. TL;DR In Python, you can use the set intersection() method or set intersection operator (&) to intersect two or more sets: new_set = set1.intersection(set2, set3) new_set = set1 & set2…
Read more

Python Set Union

Python Set Union Summary: in this tutorial, you’ll learn how to union two or more sets by using the Python set union() or set union operator (|). Introduction to the set union The union of two sets returns a new set that contains distinct elements from both sets. Suppose that you have the following sets:…
Read more

Python Set Comprehension

Python Set Comprehension Summary: in this tutorial, you’ll learn how to use the Python set comprehension to create a new set based on an existing one. Introduction to Python Set comprehension Suppose that you have the following set that consists of three tags: tags = {‘Django’, ‘Pandas’, ‘Numpy’} Code language: Python (python) To convert the…
Read more

Python Set

Python Set Summary: in this tutorial, you’ll learn about Python Set type and how to use it effectively. Introduction to the Python Set type A Python set is an unordered list of immutable elements. It means: Elements in a set are unordered. Elements in a set are unique. A set doesn’t allow duplicate elements. Elements…
Read more

Python Dictionary Comprehension

Python Dictionary Comprehension Summary: in this tutorial, you’ll learn about Python dictionary comprehension to transform or filter items in a dictionary. Introduction to Python dictionary comprehension A dictionary comprehension allows you to run a for loop on a dictionary and do something on each item like transforming or filtering, and returns a new dictionary. Unlike…
Read more

Python Dictionary

Python Dictionary Summary: in this tutorial, you’ll learn about Python Dictionary that allows you to organize related information. Introduction to the Python Dictionary type A Python dictionary is a collection of key-value pairs where each key is associated with a value. A value in the key-value pair can be a number, a string, a list,…
Read more

Python List Comprehensions

Python List Comprehensions Summary: in this tutorial, you’ll learn about Python List comprehensions that allow you to create a new list from an existing one. Introduction to Python list comprehensions In programming, you often need to transform elements of a list and returns a new list. For example, suppose that you have a list of…
Read more

How to Use the Python Reduce() function to Reduce a List into a Single Value

How to Use the Python Reduce() function to Reduce a List into a Single Value Summary: in this tutorial, you’ll learn how to use the Python reduce() function to process a list. Reducing a list Sometimes, you want to reduce a list to a single value. For example, suppose that you have a list of…
Read more

How to Filter List Elements in Python

How to Filter List Elements in Python Summary: in this tutorial, you’ll learn how to filter list elements by using the built-in Python filter() function. Introduction to Python filter() function Sometimes, you need to iterate over elements of a list and select some of them based on specified criteria. Suppose that you have the following…
Read more

How to Transform List Elements with Python map() Function

How to Transform List Elements with Python map() Function Summary: in this tutorial, you’ll learn how to use the Python map() function with lists. Introduction to the Python map() function When working with a list (or a tuple), you often need to transform the elements of the list and return a new list that contains…
Read more