How to Concatenate a Boolean to a String in Python?

Easy Solution Use the addition + operator and the built-in str() function to concatenate a boolean to a string in Python. For example, the expression ‘Be ‘ + str(True) yields ‘Be True’. The built-in str(boolean) function call converts the boolean to a string. The string concatenation + operator creates a new string by appending the … Read more

Python – List of Lists to List of Strings. How?

Coding Challenge πŸ’¬ Coding Challenge: Given a nested Python list, i.e., a list of lists. How to convert it to a string list, so that each inner list becomes a single string? Consider the following examples: 1. Input: [[‘h’, ‘e’, ‘l’, ‘l’, ‘o’], [‘w’, ‘o’, ‘r’, ‘l’, ‘d’]] Output: [‘hello’, ‘world’] 2. Input: [[‘h’, ‘i’], … Read more

How to Print Spaces in Python

Problem Formulation and Solution Overview This article will show various ways to print a single or multiple spaces in Python. Let’s say you have strings and would like to print them out to the terminal by placing a single or multiple spaces between them. πŸ’¬ Question: How would we write code to print spaces? We … Read more

How to Find the Shortest String in a Python Dictionary?

You’ll never guess the most concise way to solve this problem… πŸ¦„ Coding Challenge πŸ’¬ Challenge: Given a dictionary with string keys. Get the string key with the minimum number of characters, i.e., the shortest string. A variant of this problem is to get the length of the shortest string — I’ll give you a … Read more

Python – How to Find the Longest Substring in Alphabetical Order?

Programming Challenge πŸ’¬ Challenge: Given a Python string. Find the longest substring for which holds that all of its characters are in alphabetical order so that the first character comes earlier in the alphabet than the second character, and so on. Here are three examples: You get the point. πŸ™‚ Next, I’ll show you three … Read more

How to Find All Palindromes in a Python String?

Coding Challenge πŸ’¬ Challenge: Given a string. How to find all palindromes in the string? For comprehensibility, allow me to quickly add a definition of the term palindrome: πŸ’‘ Definition: A palindrome is a sequence of characters that reads the same backward as forward such as ‘madam’, ‘anna’, or ‘101’. This article wants to give … Read more