List initialization in python

In this article we shall see how to initialise an empty list or a list of size n initialised with a value. The list initialisation can be done in the following ways. Using the list() We can directly initialise a list using the list() keyword. This will create an empty list for us. Using [] […]

Read More

Get metadata of a python package

In this article, we shall see how to find the metadata from a python package installed via pip from the pypi.org. Python has a built-in library called importlib_metadata which can be used to obtain these data. What metadata can be obtained? This library has a class called metadata which can be used to get almost […]

Read More

You should use these three methods from the random module

We all know python has a built-in module called random which can be used to generate random numbers and other random operations. We might have used some of the methods from the random module such as randint() – This method will take two numbers and return an integer value between those limits. choice() – This […]

Read More

String rotation using python

In this article we shall see how to perform string rotation using python. With the help of the slicing operation this can be achieved in a single line in python. What is string rotation? String rotation is the concept of shifting the characters in a string either right side or left side to the current […]

Read More

Flatten a list of dictionaries

In this article we shall see how to flatten a list of dictionaries. This can be done by the following two ways. Traditional approach Dictionary comprehension If you are a beginner the traditional approach will suit you. Dictionary comprehension method is suitable for intermediate programmers. Note: Dictionary comprehension is not difficult but flattening a list […]

Read More

Copy() method in python

In this article, we shall see the copy() method in python. Python has a built-in method called copy(). This method just copies the values alone instead of copying the address just like the assignment operator. It will be much easier to look at this with an example. In order to understand what this method does, […]

Read More

Find the difference between two strings in python

Python has a lot of built-in modules and libraries. It also has a module called difflib. This module can be used to find the differences between the two strings. It is a built-in module. The difflib module has a method called ndiff. This method will take both strings and return us a generator object. We […]

Read More

Python string replace using regular expression

If you are working with strings in python, you know about a built-in method called replace(). This method will take two arguments. The pattern or substring that has to be replaced. The replacing string or characters. This method works fine. But its capabilities are limited. This is where the sub() method from the regular expression […]

Read More

Print string as ASCII art in terminal using python

In this article, we shall see how to print the string as ASCII art in terminal using python. This can be done with the help of a python package called pyfiglet. With the help of this package, we can print any string as ASCII character in the terminal with just two lines of code. Let […]

Read More

Find the common element between two lists in python

In this article we shall see how to find the elements which are common in both the lists in python. This can be easily done using one of the following two approaches. Looping Set intersection Let us look at the above methods one by one with an example for each. Looping This is a traditional […]

Read More