Last week I was designing some reading material for my Python Class. The lecture topic was Python Sets.
For illustrating some functions, I wanted to plot Venn Diagrams. Yes, the overlapping circle charts that you often find in data presentations.
My search for open-source tools for designing professional looking Venn Diagrams lead me to tools like Canva, Meta-Chart, and Creately. While they had appealing designs, none of them had the required elegance and were seldom customizable.
Somewhere in the depth of google search, I encountered matplotlib-venn and fell in love with it.
Last year I was working on a project that dealt with Twitter data. We had around a billion tweets in our database. I needed to clean our data so that we can run some machine learning models on it.
Here is a snapshot of the Dataset:
Range is a built-in Python function that returns a sequence of numbers between a start integer (
0 by default) and a stop integer.
We can iterate over the sequence generated by the
range function using a for/while loop:
print("Getting a sequence of numbers between 0 and 10")
for i in range(10):
print(i, end =' ')
# Getting a sequence of numbers between 0 and 10
# 0 1 2 3 4 5 6 7 8 9
User input is critical for building interactive programs. Every programming language has its unique implementation of an input interface. C++ has
scanf, Java has the
Scanner class, and Ruby has
While in most cases, this input stems from the keyboard, other forms like mouse clicks, track-pad, sensors, etc. are also possible.
As always, Python provides a simple framework for getting user input in the form of the
The input function reads a line from the console, converts it into a string, and returns it.
In this tutorial, we will cover the
input() function in detail using a variety of use-cases. We will discuss the several forms in which input can exist and how to parse this input into our required format with the help of code snippets. …
As millions continue to be affected by the scourge of COVID-19, the significance of simple hygiene practices like hand-washing is amplified. CDC has time and again recommended washing hands regularly, stating bluntly that it saves lives.
We are all aware of the importance of washing our hands. Hospitals supply medical practitioners with antiseptic gel before treating patients vulnerable to infection.
One would be hard-pressed to imagine a world where doctors did not sanitize or wash their hands before or after examinations. Yet, we lived in such a world just a little less than 150 years ago.
Until the late 1800s, doctors and health workers did not sanitize or even wash their hands between treating patients, even between surgeries. …
Coming from a C/C++ background, I am used to seeing a lot of semi-colons
; in code. They are used to represent statement termination.
But, Python does not mandate the use of semi-colons for delimiting statements. Yet, I often come across Python code littered with semi-colons.
Most recently, I was going through a Data Science with Python Course. The instructor was introducing conditional statements and wrote the following piece of code:
temp = 10;if temp <12: print('It is cold'); cold = True;
My reaction: Pure Horror!
Semi-colons are used only in atypical situations in Python. So, I prepared a small guide explaining why you shouldn’t use semi-colons in Python and point out the handful exceptions. …
‘We are merely explorers of infinity in the pursuit of absolute perfection.’ — G.H. Hardy
Many people think that Infinity is just a very large number. But in reality, Infinity is the idea of something being endless and without any bounds.
Since the early ages, mathematicians have gambled with this concept of endlessness. As John Green wrote in his book The Fault in Our Stars,
“Endlessness is a really strange idea in a universe that is defined by its endings.”
Infinity has many desirable properties for algorithmic design. The most popular being:
∀ x ∈ ℝ, -∞ < x <…
When Python first appeared in 1991, it was seen more as an “at your own risk” computing language. Today it is the predominant language for data science, machine learning, and software development.
A key reason behind Python’s popularity is its flexibility when it comes to adding new features and technologies like magic commands.
So, what exactly is a magic command in Python?
Magic commands are enhancements or shortcuts over the usual Python syntax designed to facilitate routine tasks.
These special commands enable us to easily control the behavior of the IPython system and solve various common problems in standard data analysis, for example, running an external script or calculating the execution time of a piece of code. …
Recently, I was working with a remote system and needed to download some images that my code will eventually process.
I could have used curl or wget on my terminal for downloading files. But, I wanted the entire process to be automated for the end-user.
This led me to the question:
How can I download an Image using Python?
Disclaimer: Do not download or use any image that violates its copyright terms.
Code used in this tutorial was tested on an Ubuntu system with Python 3.6.9 …
Last week while working on a hobby project, I encountered a very interesting design problem:
How do you deal with wrong user input?
Let me explain.