Python Built-in Functions

How to Get map() to Return a List in Python 3.x

Recap: Python’s map() function takes a function and an iterable—such as a list—as arguments. It then applies the function to each element in the iterable. It returns a map object. 🤨 But what if you don’t need a map object but a list? Old: In Python 2.x this was easy: the map() function simply returned …

How to Get map() to Return a List in Python 3.x Read More »

Python map() — Finally Mastering the Python Map Function [+Video]

The map() function transforms one or more iterables into a new one by applying a “transformator function” to the i-th elements of each iterable. The arguments are the transformator function object and one or more iterables. If you pass n iterables as arguments, the transformator function must be an n-ary function taking n input arguments. …

Python map() — Finally Mastering the Python Map Function [+Video] Read More »

How to Find the Maximum Value in a Python Dict?

There are three problem variants of finding the maximum value in a Python dictionary: Find the maximum value and return this maximum value Find the maximum value and return a (key, value) tuple of both the key and the max value itself Find the maximum value and return only the key assigned to the max …

How to Find the Maximum Value in a Python Dict? Read More »

Python’s __import__() Function — Dynamically Importing a Library By Name

Python’s built-in “dunder” function __import__() allows you to import a library by name. For example, you may want to import a library that was provided as a user input, so you may only have the string name of the library. For example, to import the NumPy library dynamically, you could run __import__(‘numpy’). In this tutorial, …

Python’s __import__() Function — Dynamically Importing a Library By Name Read More »

Python enumerate() — A Simple Illustrated Guide with Video

If you’re like me, you want to come to the heart of an issue fast. Here’s the 1-paragraph summary of the enumerate() function—that’s all you need to know to get started using it: Python’s built-in enumerate(iterable) function allows you to loop over all elements in an iterable and their associated counters. Formally, it takes an …

Python enumerate() — A Simple Illustrated Guide with Video Read More »

Python dir() — A Simple Guide with Video

If used without argument, Python’s built-in dir() function returns the function and variable names defined in the local scope—the namespace of your current module. If used with an object argument, dir(object) returns a list of attribute and method names defined in the object’s scope. Thus, dir() returns all names in a given scope. Usage Learn …

Python dir() — A Simple Guide with Video Read More »