Python Articles

Page 27 of 855

Create a stopwatch using python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

A stopwatch is used to measure the time interval between two events, usually in seconds to minutes. It has various usage like in sports or measuring the flow of heat, current etc in an industrial setup. Python can be used to create a stopwatch by using its tkinter library. This library provides GUI features to create a stopwatch showing the Start, Stop and Reset options. The key component of the program is using the label.after() method of tkinter. Syntax label.after(ms, function=None) Parameters: ms − Time in milliseconds function − Callback function to execute ...

Read More

Find all the patterns of "1(0+)1" in a given string using Python Regex

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 298 Views

In this tutorial, we will find all occurrences of the pattern "1(0+)1" in a string using Python's regex module. The re module provides powerful pattern matching capabilities for text processing. The pattern "1(0+)1" represents a literal string containing the number 1, followed by parentheses with "0+" inside, and ending with another 1. Example Input and Output Input: string = "Sample 1(0+)1 string with 1(0+)1 unnecessary patterns 1(0+)1" Output: Total number of pattern matches are 3 ['1(0+)1', '1(0+)1', '1(0+)1'] Algorithm Follow these steps to find the pattern: 1. Import the re ...

Read More

FuzzyWuzzy Python library

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 835 Views

In this tutorial, we are going to learn about the FuzzyWuzzy Python library. FuzzyWuzzy library is developed to compare strings and provides fuzzy string matching capabilities. While we have other modules like regex and difflib to compare strings, FuzzyWuzzy is unique in its approach. The methods from this library return a score out of 100 indicating how closely the strings match, instead of simple true/false or string results. Installation To work with the FuzzyWuzzy library, we need to install fuzzywuzzy and optionally python-Levenshtein for better performance − pip install fuzzywuzzy pip install python-Levenshtein The ...

Read More

Print anagrams together in Python using List and Dictionary

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 765 Views

In this tutorial, we will write a program to find and print anagrams together using list and dictionary. Anagrams are words formed by rearranging the letters of another word, like "listen" and "silent". Algorithm Here's our step-by-step approach ? 1. Initialize a list of strings. 2. Initialize an empty dictionary. 3. Iterate through the list of strings. 3.1. Sort the string and check if it is present in the dictionary as key or not. 3.1.1. If the sorted string is already present dictionary as a ...

Read More

Print first m multiples of n without using any loop in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 795 Views

In this tutorial, we will write a program to find the first m multiples of a number n without using loops. For example, if n = 4 and m = 3, the output should be 4, 8, 12 (three multiples of four). The main constraint is avoiding loops. We can use the range() function to achieve this without loops. The range() function returns a range object that generates a sequence of numbers. Syntax range(start, stop, step) Parameters start − Starting number of the range stop − Ending number (not included in the ...

Read More

Python program to count occurrences of a word in a string

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will write a program that counts the number of times a word occurs in a string. You are given a word and a string, and we need to calculate the frequency of the word in the string. Suppose we have a string "I am a programmer. I am a student." and the word "am". The program will return 2 as the word occurs two times in the string. Algorithm 1. Initialize the string and the word as two variables. 2. Split the string at spaces using the split() method to get a ...

Read More

Python program to find the IP Address of the client

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 61K+ Views

In this tutorial, we are going to find the IP address of the client using the socket module in Python. Every laptop, mobile, tablet, etc., has their unique IP address. We will find it by using the socket module. Let's see the steps to find out the IP address of a device. Algorithm Import the socket module. Get the hostname using the socket.gethostname() method and store it in a variable. Find the IP address by passing the hostname as an argument to the socket.gethostbyname() method and store it in a variable. Print the IP address. ...

Read More

Sort a list according to the Length of the Elements in Python program

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 6K+ Views

We have a list of strings and our goal is to sort the list based on the length of strings in the list. We have to arrange the strings in ascending order according to their lengths. We can do this using Python built-in method sort() or function sorted() along with a key. Let's take an example to see the output − Input: strings = ["hafeez", "aslan", "honey", "appi"] Output: ["appi", "aslan", "honey", "hafeez"] Using sorted() Function The sorted() function returns a new sorted list without modifying the original list. We pass len as ...

Read More

Reverse words in a given String in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 19K+ Views

We are given a string, and our goal is to reverse all the words which are present in the string. We can use the split() method and reversed() function to achieve this. Let's see some sample test cases. Input: string = "I am a python programmer" Output: programmer python a am I Input: string = "tutorialspoint is a educational website" Output: website educational a is tutorialspoint Python provides multiple approaches to reverse words in a string. Let's explore the most common methods. Method 1: Using split() and reversed() This approach splits ...

Read More

How to run Python code on Google Colaboratory?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 921 Views

Google Colaboratory (Colab) is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. It is hosted in Google Cloud and maintained by Google, allowing Python developers to write, run, and share code using a web browser. In this article, we will learn how to set up and use Google Colab for Python programming. Accessing Google Colab Navigate to the Google Colab website at https://colab.research.google.com/. You'll see the welcome screen with options to create a new notebook or open existing ones from various sources like GitHub, Google Drive, or upload from your computer. ...

Read More
Showing 261–270 of 8,547 articles
« Prev 1 25 26 27 28 29 855 Next »
Advertisements