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
Programming Articles
Page 622 of 2547
Python program to split the even and odd elements into two different lists.
In this article, we are going to learn about splitting the even and odd elements into two different lists. This involves looping through each element in a list and checking whether it is divisible by 2. Even numbers are those that give the remainder '0' when divided by 2, while the odd numbers leave a remainder '1'. Using append() Method The Python append() method is used to add a new object to a list. It accepts an object as an argument and inserts it at the end of the existing list. Syntax list.append(obj) ...
Read MoreSequenceMatcher in Python for Longest Common Substring.
The SequenceMatcher class is part of Python's difflib module. It compares sequences (such as lists or strings) and finds similarities between them. The task is to find the Longest Common Substring — the longest sequence of characters that appears contiguously in both strings. This is different from the Longest Common Subsequence, where characters may appear in the same order but not necessarily contiguous. Using find_longest_match() Method The find_longest_match() method finds the longest matching sequence of elements between two sequences. It returns a Match object with three attributes: a (start position in first sequence), b (start position in ...
Read MorePython program to find Maximum and minimum element’s position in a list?
In Python, Lists are one of the most versatile data types. They store sequences of comma-separated items enclosed in square brackets []. Finding the maximum and minimum element positions is a common task that can be achieved using Python's built-in functions max(), min(), and index(). Understanding the Required Functions max() Function The max() function returns the largest element in a list. For numbers, comparison is done numerically; for strings, comparison is done alphabetically. max(list) min() Function The min() function returns the smallest element in a list. Like max(), it compares numbers numerically ...
Read MoreDifference between == and is operator in python.
In Python, the == and is operators are used for comparison, but they serve different purposes. The == operator checks for equality of values, which means it evaluates whether the values of two objects are the same. On the other hand, the is operator checks for identity, meaning it determines whether two variables point to the same object in memory. What Is the 'is' Operator? The Python is operator tests whether two variables refer to the same object in memory. If the variables refer to the same memory location, it returns True; otherwise, it returns False. This operator ...
Read MoreZip function in Python to change to a new character set.
The zip() function in Python can be used to create a mapping between two character sets. This is useful when you want to translate text from one character encoding to another, such as converting from a custom character set back to the standard alphabet. Problem Statement Given a custom 26-letter character set and the standard alphabet, we need to create a mapping to translate strings from the custom set back to normal letters. Custom character set: qwertyuiopasdfghjklzxcvbnm Standard alphabet: abcdefghijklmnopqrstuvwxyz Input: "wwmm" Output: "bbzy" Algorithm Define the custom character ...
Read MorePython program to check if binary representation of two numbers are anagram.
The binary numbers are the basis of how data is stored, processed and transferred. Every integer is internally represented by using a sequence of bits (combination of 0s and 1s). In this article, we will learn how to check if binary representation of two numbers are anagram. Two numbers are said to be binary anagrams if their binary representations contain the same number of 1s and 0s. For example, the number 12 in binary is 1100 and the number 10 in binary is 1010, both have two 0s and two 1s, making them binary anagrams. Using collections.Counter() Class ...
Read MorePrint m multiplies of n without using any loop in Python.
Given a number n, we can print m multiples of a step value without using any loop by implementing a recursive function. This approach uses function calls to simulate iteration. Problem Statement We need to print numbers starting from n, decreasing by a step value until we reach 0 or negative, then increasing back to the original number. Example Input: n = 15, step = 5 Output: 15 10 5 0 5 10 15 Algorithm The recursive approach works as follows: Start with the given number n and a flag ...
Read MorePython program to find missing and additional values in two lists?
In this article, we will explore how to find missing and additional values in two lists. This type of comparison is commonly encountered in real-world scenarios such as data validation, system synchronization, and database reconciliation. The task is to determine which elements are missing in one list and what unexpected elements were received. This can be achieved by using Python's built-in data structures like sets that allow for efficient comparison operations. Understanding the Problem When comparing two lists, we need to identify: Missing values: Elements present in the first list but absent in the second list ...
Read MorePython program to check a sentence is a pangrams or not.
A pangram is a sentence that contains every letter of the alphabet at least once. For example, "The quick brown fox jumps over the lazy dog" is a famous pangram. We can check if a sentence is a pangram using Python's set() operations. Example Input and Output Input: string = 'abc def ghi jkl mno pqr stu vwx yz' Output: Yes // contains all the characters from 'a' to 'z' Input: string = 'python program' Output: No // Does not contain all the characters from 'a' to 'z' Algorithm Here's the step-by-step approach ...
Read MorePython program to extract 'k' bits from a given position?
Bit extraction involves extracting a specific number of bits from a given position in a number's binary representation. This is useful in low-level programming, cryptography, and data manipulation tasks. Understanding the Problem Given a number, we need to extract 'k' consecutive bits starting from a specific position 'pos' (counted from the right, starting at 0). The extracted bits are then converted back to decimal. Example Input: number=170, k=5, pos=2 Output: 21 Binary of 170: 10101010 Position 2 from right, extract 5 bits: 01010 Decimal value: 21 Algorithm The ...
Read More