Functions

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 Sort in Python with the Lambda Function as Key Argument?

Challenge: This article shows how to sort a Python list using the key argument that takes a function object as an argument. Quick Solution: You can use the lambda function to create the function on the fly as shown in the following example: Explanation: The code uses the key argument and passes a lambda function …

How to Sort in Python with the Lambda Function as Key Argument? Read More »

Dictionaries and Unpacking Arguments in Python

Programming is about using lower-level functionality to create higher-level functionality. In general, any programming language is a collection of functions that in turn build upon functions provided by the operating system. You must master the art of building your own code with the help of existing functionality, instead of reinventing the wheel! Keyword Arguments Functions …

Dictionaries and Unpacking Arguments in Python 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 »

Lambda Calculus in Python

This tutorial introduces an advanced language feature: lambda functions. Lambda functions are rooted in the mathematical area of lambda calculus. One of the pioneers of this area was Alonzo Church. He introduced lambda functions in 1936 even before the appearance of the first computers. Lambda functions exist in a wide range of languages for functional …

Lambda Calculus in Python Read More »

Return Keyword in Python – A Simple Illustrated Guide

Python’s return keyword commands the execution flow to exit a function immediately and return a value to the caller of the function. You can specify an optional return value—or even a return expression—after the return keyword. If you don’t provide a return value, Python will return the default value None to the caller. Python Return …

Return Keyword in Python – A Simple Illustrated Guide Read More »

Python Join Arguments and String Concatenation

Problem: Write a function that joins an arbitrary number of string arguments with a given separator. Example: Given the string arguments “A”, “B”, and “C” and the string separator “-“. Join them to the concatenated string “A-B-C”. Solution: The following code creates a Python function concat() that takes an arbitrary number of arguments, packs them …

Python Join Arguments and String Concatenation Read More »

A Guide to Python’s pow() Function

Exponents are superscript numbers that describe how many times you want to multiply a number by itself. Calculating a value raised to the power of another value is a fundamental operation in applied mathematics such as finance, machine learning, statistics, and data science. This tutorial shows you how to do it in Python! Definition For …

A Guide to Python’s pow() Function Read More »

Captive User Interfaces — Why You Should Avoid Them

This tutorial shows you the meaning of captive user interfaces and why they’re discouraged under the Unix philosophy. I’ve written this as a first chapter draft for my upcoming book “From One to Zero” to appear in 2020 with San Francisco-based publisher NoStarch. What’s a Captive User Interface (CUI)? A captive user interface is a …

Captive User Interfaces — Why You Should Avoid Them Read More »