Python | Join List as Path

Do you want to join a list of strings to a path in your specific operating system? Remembering the correct path separator can be a real pain. Fortunately, the os.path.join() method comes to the rescue! The os.path.join() method takes one or more path arguments and returns a concatenation of the path arguments with the correct … Read more

String Formatting: Keep It Simple, Stupid!

What is the output of this code snippet? The string format function is a useful feature that is new in Python 3. Use it to programmatically insert variable values into the string. Without the format function, you must break the string into a series of smaller substrings and concatenate them. For example, the last line … Read more

List Indexing

🛑 Note: Python has zero-based indexing, i.e., the index of the first element is 0, and the index of the i-th element is (i-1). This is a common source of bugs! What is the output of this code snippet? This puzzle introduces the simple but powerful list data structure in Python. You have to search … Read more

Set, Lambda, and Filter in Python

Social Media

What is the output of this code snippet? You will use or have already used the operations introduced in this puzzle. They are elementary pieces of knowledge for any Python programmer. First, we have the two dictionaries mapping an account name to the number of followers. For example, Cristiano Ronaldo (key: “@cristiano”) has 120 million … Read more

Parameter Passing in Python: Call By Object

What is the output of this code snippet? This puzzle demonstrates that parameters are called by object in Python. What does that mean? We look into two functions depreciation1 and depreciation2. The functions take an asset value or a list of asset values as inputs. They depreciate this value by multiplying it with the depreciation … Read more

How to Join List of Unicode Strings in Python? ‘?’

To join a list of Unicode strings in Python, use the string.join(list) method on the delimiter string. For example, you can call ‘?’.join([‘⭐’, ‘?’, ‘?’]) to obtain the string ‘⭐????’. Note that per default, all strings are UTF-8 in Python which means they already are Unicode encoded. This morning—when reading a WhatsApp message during my … Read more

String Indexing in Python (2-Min Tutorial)

What is the output of this code snippet? This puzzle introduces a powerful tool for your Python toolbox. Make sure, you feel comfortable using it because many advanced puzzles depend on it. The name of the tool is indexing. In Python, you can access every character in the string by using an integer value which … Read more

Python Division: A Short Guide

Python Division

What is the output of this code snippet? The majority of people solve this puzzle correctly. Even so, the first goal of this puzzle is to introduce the concept of variables. Python evaluates the result of the expression on the right side of the equation and stores it in the variable x. After defining the … Read more