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 621 of 2547
Python program to print all sublists of a list.
A sublist is a portion of a list containing one or more elements from the original list. Sublists can be contiguous (elements appear in the same order as the original) or non-contiguous (elements are taken from different positions). Printing Contiguous Sublists Using Nested Loops Contiguous sublists maintain the original order of elements. We can generate them using nested loops ? def print_contiguous_sublists(items): for i in range(len(items)): for j in range(i, len(items)): print(items[i:j+1]) ...
Read MoreConcatenated string with uncommon characters in Python?
In Python, Strings are one of the commonly used data types that are used to store sequences of characters. In this article, we are going to learn to concatenate strings with uncommon characters in Python. The uncommon characters are the characters that appear in one string but not in the other string. For example, if str1="ABC" and str2="BCD", the uncommon characters are 'A' and 'D', and the concatenated result is "AD". Using set.symmetric_difference() Method The set.symmetric_difference() method returns a new set that contains elements present in either of the sets, but not in both. This makes it ...
Read MorePython program to print all the common elements of two lists.
Given two lists, we need to find and print all the common elements between them. Python provides several approaches to solve this problem efficiently. Examples Input : list1 = [5, 6, 7, 8, 9] list2 = [5, 13, 34, 22, 90] Output : {5} Explanation The common element between both lists is 5, which appears in both lists. Using Set Intersection Convert both lists to sets and use the intersection operator (&) to find common elements ? def find_common_elements(list1, list2): ...
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 MorePython program to display Astrological sign or Zodiac sign for a given data of birth.
In this article, we'll learn how to determine the astrological sign or zodiac sign for a given date of birth. We'll compare the user's birthdate with predefined date ranges for each zodiac sign using Python programming logic. The 12 astrological sun signs, also known as zodiac signs, are based on specific periods throughout the year. Each sign corresponds to a particular range of dates ? Aries (March 21 − April 19) Taurus (April 20 − May 20) Gemini (May 21 − June 20) Cancer (June ...
Read MorePython program to create 3D list.
In Python, a 3D list is also called a three-dimensional array (list of lists of lists). It can be visualized as a cube or a set of tables stacked together. It is commonly used to represent data with three indices, such as a matrix of images (height, width, depth) or storing data for multiple 2D grids. In this article, we will learn how to create a 3D list. While Python doesn't have built-in support for multi-dimensional arrays like other programming languages, we can create and manipulate 3D lists using nested lists and loops. Using Nested Loops The ...
Read MorePython program to Display Hostname and IP address?
In this article, we are going to learn how to display the hostname and IP address. Generally, the devices that connect to a network are identified by two things: Hostname: It is the name assigned to the device on a network. It helps users to identify devices in a human-readable format (e.g, mypc, desktop-pc, etc.) IP Address: It is the numerical address assigned to each device on a network, used to locate and communicate with that device. Python provides the built-in socket module for achieving this task, which ...
Read MorePython program to reverse bits of a positive integer number?
In Python, every number is represented internally as a sequence of binary digits, known as bits. In this article, we are going to learn how to reverse the bits of a positive integer number using different approaches. What is Bit Reversal? When we reverse bits of an integer value, we flip the order of its binary digits such that the least significant bit becomes the most significant bit and vice versa. Bit Reversal Example Original: 10 1 0 ...
Read MorePython program to find the length of the largest consecutive 1's in Binary Representation of a given string.
Given a number, we need to find the length of the longest consecutive 1's in its binary representation. This problem can be solved using bit manipulation techniques. Example Input: n = 15 Output: 4 The binary representation of 15 is 1111. Algorithm The algorithm uses bit manipulation to count consecutive 1's: Step 1: Input the number Step 2: Use a counter variable to track iterations Step 3: Apply bitwise AND with left-shifted number Step 4: This reduces each sequence of 1's by one in each iteration Step 5: Count iterations until the number becomes 0 Using Bit Manipulation This method uses the property that n & (n
Read MorePython program to print the initials of a name with last name in full?
In this article, we are going to learn how to print the initials of a name with last name in full. For example, in applications like resumes or media references, instead of writing "Sai Vamsi Srinivas", we might write "S.V. Srinivas". This kind of formatting improves readability and ensures the important part of the name (last name) is fully visible. Using Python split() and join() Methods The Python split() method splits all words in a string using a specified separator. The separator can be a space, comma, or any other character. Following is the syntax ? ...
Read More