If-Then-Else in One Line Python

Quick answer: How to put a simple if-then-else statement in one line of Python code? To put an if-then-else statement in one line, use Python’s ternary operator x if c else y. This returns the result of expression x if the Boolean condition c evaluates to True. Otherwise, the ternary operator returns the alternative expression … Read more

Python Find Longest List in List

Problem Formulation πŸ’¬ Programming Challenge: Given a list of lists (nested list). Find and return the longest inner list from the outer list of lists. Here are some examples: [[1], [2, 3], [4, 5, 6]] πŸ‘‰ [4, 5, 6] [[1, [2, 3], 4], [5, 6], [7]] πŸ‘‰ [1, [2, 3], 4] [[[1], [2], [3]], [4, … Read more

How to Scrape the Details of 250 Top Rated Movies in Python

This article indicates a way to scrape imdb.com/chart/top/, a website that contains 250 numbers of top-rated Movies. This article is solely for educational purposes. πŸ‘‰ Recommended Tutorial: Web Scraping – Is It Legal? The tool used to extract data from a website is Scrapy, and the software system is UNIX operating system. Virtual Environment Set … Read more

How to Extract Google Featured Snippets Using Python?

The article begins by formulating a problem relating to website click-through rate and gives you an overview of solutions about how to extract Google Featured Snippets using Python. And the article goes into great detail about the solution for beginners. At the end of this article, you will see the results of extracting featured snippets … Read more

Python One Line Ternary

The most basic ternary operator x if c else y consists of three operands x, c, and y. It is an expression with a return value. The ternary operator returns x if the Boolean expression c evaluates to True. Otherwise, if the expression c evaluates to False, the ternary operator returns the alternative y. Ternary … Read more

Solidity File Layout – SPDX License ID and Version Pragmas

In the previous articles, we looked at some of the representative examples of smart contracts representing possible real-world scenarios. Our main focus was on capturing the essence of each case, without particular attention given to the general structure, i.e. layout of the respective source files. However, in this mini-series starting with this article, we will … 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

5 Ways to Check If a Dictionary is Empty in Python

Problem Formulation and Solution Overview This article will show you how to check if a Dictionary is empty in Python. Before moving forward, let’s review what a Python Dictionary is. πŸ’‘Dictionary Overview: The Python Dictionary is a data structure that houses key:value pairs of data. This data structure does not allow duplicate keys, thus ensuring … Read more

How to Find the Shortest String in a Python Set?

Use Python’s built-in min() function with the key argument to find the shortest string in a set. Call min(my_set, key=len) to return the shortest string in the set using the built-in len() function to determine the weight of each stringβ€”the shortest string has minimum length. πŸ‘‰ Recommended Tutorial: How to Find the Shortest String in … 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