Found 10784 Articles for Python

Python Program to Find Unique Lines From Two Text Files

Saba Hilal
Updated on 10-Jul-2023 15:52:36

223 Views

Many times we see two files that look similar but had certain differences. If the files are big or have lots of content, searching for that difference or finding the uniqueness in that file manually is not easy. However, this problem of finding the unique lines in two text files can be done easily using Python programs. In this article, using three different examples, three different ways of finding the unique lines in two text files are given. The text files used are a.txt and b.txt while in the end the result is stored in another txt file. For these ... Read More

Python program to find start and end indices of all Words in a String

Saba Hilal
Updated on 10-Jul-2023 15:50:05

186 Views

Sometimes, we require starting index of a word and also the last index of that word. A sentence is made up of words that are separated by spaces. In this Python article, using two different examples, the two different ways of finding the beginning and ending indices of all words in a sentence or a given string, are given. In the first example, the process of simple iteration through all the characters of a string is followed while finding the spaces to mark the beginning of words. In example 2, a Natural Language Toolkit is used for the task of ... Read More

Python Program to Get Sum of N Armstrong Numbers

Saba Hilal
Updated on 10-Jul-2023 15:46:46

100 Views

A number is said to be an Armstrong number if the digits are taken individually and raised to the power of the total digits and then these subparts are added together and they give the number itself. Here, in this Python example, using two different examples, the method of finding the total sum of n-digit Armstrong numbers is given. In example 1, the method to calculate the sum of all the 3 digit Armstrong numbers is given. In example 2, the number of digits can be decided by the user at runtime. This program is tested using digit values 4 ... Read More

Python Program to find Sum of Negative, +ve Even and +ve Odd numbers in a List

Saba Hilal
Updated on 10-Jul-2023 15:41:43

508 Views

Sometimes the task is to separate the negative and positive numbers or to separate the odd numbers and even numbers from a list of integers. Here, in this Python article, both these tasks are done. First negative numbers are separated into another list. Then the positive odd and positive even numbers are separated into separate lists. To calculate the sum, the numbers from these negative number lists, positive odd number lists, and positive even number lists are taken to calculate sums separately. In the two different examples, the main list of integers is formed. In example 1, the negative and ... Read More

Python Program to Find Numbers Divisible by 7 and Multiple of 5 in a Given Range

Saba Hilal
Updated on 10-Jul-2023 15:38:57

929 Views

A multiple of a number n is also divisible by the same number n. If a number M is a multiple of a number n, then if we divide M by n, its remainder must be zero. Also to create the multiples of number n within a given range, we can add n multiple times and check that the resulting number is within the given range or not. Another way to make multiples of a given number n, within a given range, is to find the first multiple in the given range for n and then to find the value ... Read More

Python program to find the string weight

Saba Hilal
Updated on 10-Jul-2023 15:29:07

385 Views

In this article, the given task is to find the total string weight. To calculate the string weight, we have converted the given strings into the lower form. Considering the weight of the characters, we have taken a=1, b=, 2 and so up to z=26. In this Python article, using two different examples, the approaches to find the given string’s weight are given. In the first example, given characters in a string are fetc, hed, and then their respective weight is added to the updated weight. In example 2, first the frequency of occurrence of a given character in the ... Read More

Fastest way to Convert Integers to Strings in Pandas DataFrame

Rohan Singh
Updated on 10-Jul-2023 14:07:07

3K+ Views

In Python there are many methods to convert Integers to strings in Pandas Dataframe like astype() method, apply() method, map() method, list comprehension, etc. Out of all these methods, the fastest way to convert Integers to string in Pandas data frame can be determined by tracking the time taken by each method for conversion. In this article, we will understand how to convert integers to string in a pandas data frame using all four methods and then track the time taken by each for conversion. Method 1: Using the List comprehension method In this method, we create a list of ... Read More

Facts App Using Tkinter module

Rohan Singh
Updated on 10-Jul-2023 14:03:46

106 Views

In Python, we can use Tkinter module and randfacts module to create a Facts generator App. Tkinter is a Python GUI toolkit that is used to create graphical applications. You can create buttons, labels, text boxes, and other types of widgets using the Tkinter library. The randfacts is a Python module that generates random facts. In this article, we will implement a Fact App Generator GUI application using Tkinter and the randfacts module. Creating the Facts Generator App To create the facts generator app we first need to install the randfacts module using the Python package manager. To install ... Read More

Facts about Cython Programming Language

Rohan Singh
Updated on 10-Jul-2023 13:58:37

133 Views

Cython is a programming language that is a superset of Python and can be compiled into C code for improved performance. Cython is developed to improve the execution speed and make the code faster compared to Python. In this article, we will look at some interesting facts about Cython Programming Language. Cython can be used to speed up Python code As the name suggests Cython is Python-like code that can be converted to C code for faster and improved execution speed. Developers can write code in Python which is then compiled into C code and makes the language much faster. ... Read More

Extracting locations from text using Python

Rohan Singh
Updated on 10-Jul-2023 13:44:30

2K+ Views

In Python, we can extract location from text using NLP libraries available in Python such as NLTK, spaCy, and TextBlob.Extracting location from text is used in various Natural language processing tasks such as sentiment analysis, information retrieval, and social media analysis. In this article, we will discuss how we can extract location from text using the spaCY library. Prerequisites Installing spaCY library Before using the scpaCy library for the extraction process you need to install the spaCy library using pip command in Python. To extract the spaCy library you can type the following command in your terminal or ... Read More

Advertisements