Found 10476 Articles for Python

Create Word Cloud using Python

Akshitha Mote
Updated on 23-Jun-2025 17:12:23

1K+ Views

A "word cloud" is a visual representation of text data, where the size of each word indicates its frequency or importance within the dataset. It helps us to identify the most common and important words in a text. It is typically used to describe/denote big data in a word. In this article, we will create a word cloud on the Python programming language, and the data is accessed from Wikipedia. Modules to create a Word Cloud in Python Following are the modules required to create a word cloud in Python : Install wordcloud Before installing the word cloud module, you have ... Read More

How to convert HTML to PDF using Python

Akshitha Mote
Updated on 23-Jun-2025 17:08:48

2K+ Views

In general, we look at some external websites to convert our files to PDF format; instead, we can convert them using Python on our own. In this article, we will understand the steps to convert the HTML (Hyper Text Markup Language) to PDF using Python code. Steps to convert HTML to PDF Following are the steps to convert the HTML file to PDF using Python: Step 1: Installation Download the pdfkit library by running the following command in the command prompt: pip install pdfkit Step 2: Download wkhtmltopdf Following are the steps to download wkhtmltopdf: ... Read More

Python program to sort a list according to the second element in the sublist.

AmitDiwan
Updated on 11-Aug-2022 08:56:19

1K+ Views

In this article, we will sort a list according to the second element in the sublist. Let’s say we have the following list − [['jack', 50], ['antony', 20], ['jones', 87], ['gary', 70], ['tom', 90], ['sam', 110], ['warner', 65]] The output should be the following i.e. sorted according to the second element − [['antony', 20], ['jack', 50], ['warner', 65], ['gary', 70], ['jones', 87], ['tom', 90], ['sam', 110]] Python program to sort a list according to the second element in the sublist using the sort() method Example # Custom Function def SortFunc(sub_li): sub_li.sort(key = lambda x: x[1]) return sub_li ... Read More

Python program to calculate BMI(Body Mass Index) of your Body

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

We have to enter our height and weight. Our task is to calculate BMI using formula. Algorithm Step 1: input height and weight of your body. Step 2: then applying the formula for calculation BMI. Step 3: display BMI. Example Code height = float(input("Enter your height(m): ")) weight = float(input("Enter your weight(kg): ")) print("Your BMI is: ", round(weight / (height * height), 2)) Output Enter your height (m): 5.8 Input your weight (kg): 64 Your body mass index is: 1.9

Python program multiplication of two matrix.

Samual Sam
Updated on 30-Jul-2019 22:30:23

20K+ Views

Given two user input matrix. Our task is to display the addition of two matrix. In these problem we use nested List comprehensive. Algorithm Step1: input two matrix. Step 2: nested for loops to iterate through each row and each column. Step 3: take one resultant matrix which is initially contains all 0. Then we multiply each row elements of first matrix with each elements of second matrix, then add all multiplied value. That is the value of resultant matrix. Example Code # Program to multiply two matrices A=[] n=int(input("Enter N for N x N matrix: ")) ... Read More

Python program for Modular Exponentiation

Akshitha Mote
Updated on 23-Jun-2025 17:26:07

835 Views

What is Modular Exponentiation? To calculate Modular exponentiation, we need to raise a base to an exponent and then calculate the modulus of the result. This includes 3 integers: base, exponent, and modulo. Following is the syntax of the modular exponentiation in Python - (base**exponent) % modulo For instance, consider (2^5) % 5, which indicates 2 raised to the power of 5, which results in 32; When the modulo operation is performed, it returns the remainder, i.e., 32 % 5 is 3. Modular Exponentiation using Recursive Function A function that calls itself is known as a recursive function. Following is ... Read More

String slicing in Python to rotate a string

karthikeya Boyini
Updated on 23-Jun-2020 16:09:07

5K+ Views

A string is given, our task is to slicing the string into two way. One is clockwise and another anticlockwise.1. Left (Or anticlockwise) rotate the given string by d elements (where d pythonprogram Left Rotation: thonprogrampy Right Rotation: ampythonprogr

Python program to move spaces to front of string in single traversal

Samual Sam
Updated on 23-Jun-2020 16:09:23

500 Views

Given a string that has set of words and spaces, our task is to move all spaces to front of string, by traversing the string only once. We will solve this problem quickly in Python using List Comprehension.ExampleInput: string = "python program" Output: string= “ pythonprogram"AlgorithmStep1: input a string with word and space. Step2: Traverse the input string and using list comprehension create a string without any space. Step 3: Then calculate a number of spaces. Step 4: Next create a final string with spaces. Step 5: Then concatenate string having no spaces. Step 6: Display string.Example Code# Function to ... Read More

Program to check if a number is Positive, Negative, Odd, Even, Zero?

Samual Sam
Updated on 17-Jun-2025 15:57:24

7K+ Views

In this article, we are going to learn how to check if the number is positive, negative, odd, even, or zero. Identifying and categorizing a number based on its characteristics is a basic operation. A number can fall into multiple categories: Positive: A number is greater than 0. Negative: A number less than 0. Zero: The number that is equal to 0. Even: The number that is divisible by 2. Odd: The number that is not divisible by 2. Let's dive into the ... Read More

Python program to print all sublists of a list.

Yaswanth Varma
Updated on 17-Jun-2025 17:27:58

6K+ Views

Printing sublists in PythonThe sublist is a portion of the list that contains one or more elements from the original list. These sublists can be contiguous(elements appear in the same order) or non-contiguous(where elements are taken from different positions). Example: Printing all Contiguous SublistsLet's look at the following example, where we are going to print all the contiguous sublists of the given list using nested loops. def demo(a): for i in range(len(a)): for j in range(i, len(a)): print(a[i:j+1]) x ... Read More

Advertisements