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 Samual Sam
Page 3 of 151
Underscore(_) in Python
In Python, the underscore (_) character has several special uses and naming conventions. Understanding these patterns helps you write more Pythonic code and follow established conventions. Single Underscore in Interpreter The Python interpreter automatically stores the result of the last expression in the special variable _ ? # In interactive Python interpreter print(10 + 5) print(_) # Access last result print(_ * 2) # Use it in calculations 15 15 30 Ignoring Values in Unpacking Use _ as a throwaway variable when you don't need certain values during ...
Read MoreMerge two sorted arrays in Python using heapq?
The heapq module in Python provides an efficient way to merge multiple sorted iterables into a single sorted sequence. The heapq.merge() function is specifically designed for merging sorted arrays while maintaining the sorted order. The heapq.merge() Function The heapq.merge() function accepts multiple sorted iterables and returns an iterator that produces elements in sorted order. It uses a min-heap internally to efficiently merge the arrays without loading everything into memory at once. Syntax heapq.merge(*iterables, key=None, reverse=False) Basic Example Here's how to merge two sorted arrays using heapq.merge() ? import heapq ...
Read MoreCreate a Website Alarm Using Python
In this section we will see how to create a website alarm system using Python. This tool automatically opens a specified website URL in your browser at a predetermined time. Problem Statement Create a program that opens a website URL on the browser by taking a website URL and time as input. When the system time reaches the specified time, the webpage will be opened automatically. We can store different web pages in our bookmark sections. Sometimes we need to open some web pages every day at a specific time to do some work. For that purpose, ...
Read MoreUnix filename pattern matching in Python
Unix filename pattern matching in Python is accomplished using the fnmatch module. This module provides shell-style pattern matching capabilities to compare filenames against patterns and returns True or False based on matches. Importing the fnmatch Module First, import the fnmatch module from Python's standard library ? import fnmatch Unix Wildcard Patterns The fnmatch module supports standard Unix wildcards ? * − Matches any number of characters (including none) ? − Matches exactly one character [seq] − Matches any character in the sequence [!seq] − Matches any character not in the sequence ...
Read MorePython program multiplication of two matrix.
Matrix multiplication is a fundamental operation in linear algebra where we multiply two matrices to produce a resultant matrix. In Python, we can implement matrix multiplication using nested loops and list comprehensions. Algorithm Step 1: Input two matrices of compatible dimensions Step 2: Initialize a result matrix with zeros Step 3: Use three nested loops: - Outer loop for rows of first matrix - Middle loop for columns of second matrix - Inner loop for dot product calculation Step 4: For each position (i, j), multiply ...
Read MorePython program to move spaces to front of string in single traversal
Given a string that has set of words and spaces, our task is to move all spaces to front of string, by traversing the string only once. We will solve this problem quickly in Python using list comprehension. Example Input: string = "python program" Output: string = " pythonprogram" Algorithm The algorithm follows these steps: Input a string with words and spaces Traverse the input string using list comprehension to extract non-space characters Calculate the number of spaces in ...
Read MoreProgram to check if a number is Positive, Negative, Odd, Even, Zero?
In this article, we are going to learn how to check if the number is positive, negative, odd, even, or zero. Identifying and categorizing a number based on its characteristics is a basic operation. A number can fall into multiple categories: Positive: A number is greater than 0. Negative: A number less than 0. Zero: The number that is equal to 0. Even: A number that is divisible by 2. Odd: A number that is not divisible by ...
Read MorePython Program to calculate n+nm+nmm.......+n(m times).
Here we need to calculate a series where each term is formed by repeating digit n multiple times: n + nn + nnn + ... up to m terms. For example, if n=3 and m=4, the series would be 3 + 33 + 333 + 3333. Algorithm Step 1: Input n and m values Step 2: Convert n to string for concatenation Step 3: Initialize sum with first term (n) Step 4: Build each term by concatenating n repeatedly Step 5: Convert string back to integer and add to sum Step 6: Return final sum ...
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 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 More