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

Add seconds, minutes, hours and days in python

This article teaches you how to add seconds, minutes, hours, and days to the datetime object in python. The datetime module in python has a special class called timedelta. This class enables us to make these operations to the datetime object and also return the datetime object. The following topics are discussed here. Adding seconds […]

Read More

Multiple ways to format and print in python

In this article, we shall see how to print data to the console using python. We all know that the print() method can be used to print data to the console. This article mainly focuses on the multiple ways by which can format the data before printing it out on the console. The following methods […]

Read More