How To Sort A Set Of Values?

Summary: This blog explores the steps to sort elements of a Set. Python offers the built-in sorted() function to sort elements in container objects such as a set or a list. For example: sorted({1, 5, 2}) sorts the elements in the set and returns the sorted list [1, 2, 5]. Note: All the solutions provided … Read more

Striving for Collective Intelligence

The idea I’m going to tell you is well-researched but little-known. And it’s meta. Thinking about it has become my main passion, life mission, and purpose. It’s how I see the world. In short: what drives me is increasing collective intelligence. Collective Intelligence is Everywhere You are not one individual but many individual cells that are … Read more

Python String to Float – A Simple Illustrated Guide

Summary: To convert a string object to float object use the float(string_input) method which typecasts the string input to a floating-point value. Introduction Before learning how to convert a string object to a float object, let us understand what is type conversion in Python. ✎ The process of converting an object of a particular data … Read more

How to Check if a Key Exists in a Python Dictionary?

Summary: To check whether a key exists in a dictionary, you can use: The in keyword The keys() method The get() method The has_key() method Overview Mastering dictionaries is one of the things that differentiates the expert coders from the intermediate coders. Why? Because dictionaries in Python have many excellent properties in terms of runtime—and … Read more

[Solved] NumPy RuntimeWarning: All-NaN slice encountered

Problem Formulation You use NumPy’s np.nanmedian() function in your code that is supposed to ignore NaN values when computing the mean of a NumPy array. But when using it, NumPy raises a RuntimeWarning: All-NaN slice encountered message: What is the reason for this warning and how to fix it? Solution + Explanation The reason this … Read more

[Solved] NumPy RuntimeWarning: Mean of empty slice

Problem Formulation You use NumPy’s np.nanmean() function in your code that is supposed to ignore NaN values when computing the mean of a NumPy array. But when using it, NumPy raises a RuntimeWarning: Mean of empty slice message: What is the reason for this warning and how to fix it? Solution + Explanation The reason … Read more

A Simple Introduction to Set Comprehension in Python

Being hated by newbies, experienced Python coders can’t live without this awesome Python feature. In this article, I give you everything you need to know about set comprehensions using the bracket notation {}. What is Set Comprehension? Set comprehension is a concise way of creating sets in Python using the curly braces notation {expression for … Read more

How to Get an HTML Page from a URL in Python?

This tutorial shows you how to perform simple HTTP get requests to get an HTML page from a given URL in Python! Problem Formulation Given a URL as a string. How to extract the HTML from the given URL and store the result in a Python string variable? Example: Say, you want to accomplish the … Read more