This article will teach you how to determine whether a string contains a URL or not. In Python, strings are collections of bytes that represent Unicode characters. When given a string, we will first determine whether it contains a URL and then extract it using regular expressions. Using findall() Method We will use Python's regular expression concept to solve this problem. Regular expressions are supported by the Python re module. The findall() method returns a list of all matches found in the string, scanning from left to right. Syntax re.findall(pattern, string) Example ... Read More
To insert Python objects like tuples, lists, or dictionaries into a MySQL database, you need to establish a connection and use parameterized queries. This tutorial shows how to safely insert Python data structures into MySQL tables. Prerequisites First, install the PyMySQL module and ensure you have a MySQL database with an employee table ? pip install PyMySQL Create the employee table structure ? CREATE TABLE employee ( fname VARCHAR(50), lname VARCHAR(50), age INT, gender CHAR(1), ... Read More
List is a built-in data structure in python which functions like a dynamically sized array. Lists are created by putting elements in square brackets [element1, element2, ....]. Elements present in list are indexed and the indexing starts from [0]. List has the following properties − List is mutable meaning that elements can be added, removed or changed from a list after its creation. List is ordered, so adding new elements to the list ... Read More
This article demonstrates how to sort a list of tuples by their float elements in Python. We'll explore three different approaches: using sorted(), using sort(), and implementing bubble sort manually. Input-Output Scenarios The following scenarios show how tuples are sorted by their float elements in descending order ? Scenario 1 Input: data = [('Dengue', '54.865'), ('Malaria', '345.743'), ('Corona', '456.864'), ('Typhoid', '35.285'), ('Jaundice', '83.367')] Output: [('Corona', '456.864'), ('Malaria', '345.743'), ('Jaundice', '83.367'), ('Dengue', '54.865'), ('Typhoid', '35.285')] Scenario 2 Input: data = [('638', '54.865'), ('932', '345.743'), ('256', '456.864'), ('843', '35.285'), ('246', '83.367')] Output: [('256', ... Read More
This article teaches you how to write a Python program to find mirror characters in a string. A mirror character is the alphabetically opposite character − 'a' mirrors to 'z', 'b' to 'y', and so on. Understanding Mirror Characters Mirror characters are pairs of letters that are equidistant from both ends of the alphabet. For example: 'a' (1st letter) mirrors to 'z' (26th letter) 'b' (2nd letter) mirrors to 'y' (25th letter) 'c' (3rd letter) mirrors to 'x' (24th letter) Input-Output Example Given a string and a position, we mirror characters from that ... Read More
Matrix refers to a collection of numbers arranged in rows and columns to form a rectangular array. The numbers make up the matrix's entries, or elements. We need to create a Python function to determine whether two given matrices are identical. In other words, we say that two matrices are identical if all of the elements in their respective places are the same. Identical Matrices Two matrices are only considered equal if and when they meet the requirements listed below − There should be an equal number of rows and columns ... Read More
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. Required Modules Following are the modules required to create a word cloud in Python − Install wordcloud Before installing the word cloud module, you have ... Read More
Converting HTML to PDF programmatically is a common requirement for generating reports, invoices, or documentation. Python provides several libraries for this task, with pdfkit being one of the most popular options as it leverages the powerful wkhtmltopdf engine. In this article, we will explore how to convert HTML files to PDF using Python with the pdfkit library. Prerequisites and Installation Step 1: Install pdfkit Library First, install the pdfkit library using pip − pip install pdfkit Step 2: Install wkhtmltopdf The pdfkit library requires wkhtmltopdf as its backend engine. Follow these ... Read More
In this article, we will learn how to sort a list according to the second element in each sublist. This is useful when working with data where each item is a pair, such as name-score pairs or key-value combinations. 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 sorted according to the second element ? [['antony', 20], ['jack', 50], ['warner', 65], ['gary', 70], ['jones', 87], ['tom', 90], ['sam', 110]] Using sort() Method The ... Read More
Body Mass Index (BMI) is a measure used to determine whether a person has a healthy body weight for their height. The BMI formula is: BMI = weight (kg) / height² (m²). Algorithm Step 1: Input height in meters and weight in kilograms Step 2: Apply the BMI formula: weight / (height × height) Step 3: Display the calculated BMI value Step 4: Interpret the BMI category Basic BMI Calculator Here's a simple program to calculate BMI − height = float(input("Enter your height (m): ")) weight = float(input("Enter your weight (kg): ")) ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance