Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Sumana Challa
26 articles
Minkowski distance in Python
The Minkowski distance is a metric in a normed vector space that measures the distance between two or more vectors. This metric is widely used in machine learning algorithms for measuring similarity between data points. The formula for calculating Minkowski distance is: D = (Σ|ri - si|p)1/p i=1 n Where: ri and si: Corresponding elements of two vectors in n-dimensional space p: Order parameter that determines the distance type. ...
Read MorePython program to convert floating to binary
A floating-point number is a number that has a decimal point and can represent both large and very small values. Binary representation uses only 0's and 1's in the base-2 numeral system. Converting floating-point numbers to binary in Python requires representing them in the IEEE 754 format (a standard for numerical representation using 1 bit for sign, 8 bits for exponent, and 23 bits for significand in 32-bit format). For example, the floating number 9.87 has the IEEE 754 32-bit binary representation "01000001000111011110101110000101". In this article, we will discuss different ways to convert floating-point numbers to binary using ...
Read MoreGet similar words suggestion using Enchant in Python
There will be times when we misspell some words when we write something. To overcome this problem, we use the PyEnchant module in Python. This module is used to check the spelling of words and suggest corrections for misspelled words. It is also used in many popular spell checkers, including ispell, aspell, and MySpell. It is very flexible in handling multiple dictionaries and multiple languages. For example, if the input is 'prfomnc', then the output returned would be − 'prominence', 'performance', 'preform', 'provence', 'preferment', 'proforma'. Installing PyEnchant For Windows users, install the pre-built binary packages using ...
Read MoreFind all the patterns of \"10+1\" in a given string using Python Regex
The term "10+1" is a specific pattern in a binary string that starts with a digit '1' followed by at least one or more '0' and ending with a '1'. In regular expressions, this pattern is represented as 10+1. Understanding the Pattern The regex pattern 10+1 breaks down as follows ? 1 − matches the literal character '1' 0+ − matches one or more occurrences of '0' 1 − matches the literal character '1' Using re.findall() The re.findall() method accepts a pattern and a string as parameters, finds the given pattern in the ...
Read MoreHow can I remove the same element in the list by Python
A list is a built-in Python data structure that stores an ordered collection of items. Lists often contain duplicate elements, which can cause data inaccuracies. In this article, we will explore several approaches to remove duplicate elements from a list while preserving the original order. Using set() Function The set() function accepts an iterable (like a list, tuple, or string) as a parameter and creates a set object. Since a set object does not accept duplicate values, converting a list to a set automatically removes duplicates. Example The following example removes duplicate elements using the set() ...
Read MoreHow to print Narcissistic(Armstrong) Numbers with Python?
A narcissistic number (also known as an Armstrong number) is a number that equals the sum of its digits, each raised to the power of the number of digits. For example, 370 = 33 + 73 + 03 = 27 + 343 + 0 = 370. Algorithm Steps The algorithm to check for an Armstrong number follows these steps ? Determine the number of digits for the mentioned number. Extract each digit and calculate the power of that digit with the exponent equal to the number of digits. ...
Read MoreHow to clamp floating numbers in Python?
Clamping refers to limiting a number to a specific range, ensuring that the number lies between the minimum and maximum values. This method is used in applications like graphics and statistical computations, as it requires data to stick to specific limits. Creating a User-Defined Function Since Python has no built-in clamp function, we can create our own clamp() function that takes three parameters − n (number to be clamped), min_val (minimum value), and max_val (maximum value) ? def clamp(n, min_val, max_val): if n < min_val: ...
Read MoreHow to convert numbers to words using Python?
Converting numbers to words is a common requirement in applications like check writing, invoice generation, and text-based reports. Python's num2words library provides a simple way to convert numerical values to their word representations. For example, converting 1, 2, 29 to "one", "two", "twenty-nine" respectively. Installing the num2words Library Before using the library, install it using pip − pip install num2words Basic Number to Words Conversion The num2words() function converts integers and floats to their word equivalents − from num2words import num2words # Convert simple integers print(num2words(42)) # ...
Read MoreHow to bitwise XOR of hex numbers in Python?
The bitwise XOR is a binary operation that compares two binary numbers bit by bit and returns "1" if the bits are different, and "0" if they are the same. The XOR (exclusive OR) operation follows these rules ? A B A ⊕ B ...
Read MoreHow to divide large numbers using Python?
Python allows you to perform basic mathematical operations like addition, subtraction, multiplication, and division on large numbers. Python's integers are arbitrary-precision, meaning there is no limit on their size. However, dividing large numbers has some considerations: Regular division results in floating-point numbers, which have precision limitations (15-17 decimal digits) For high-precision results, you need special approaches Python provides multiple division methods: regular division (/), floor division (//), and the decimal module Let us explore each approach with examples ? Using Division Operator (/) The ...
Read More