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 on Trending Technologies
Technical articles with clear explanations and examples
Python Program to Replace occurrences by K except first character
Python provides several methods to replace all occurrences of a character except the first occurrence. This is useful when you want to preserve the first instance while modifying subsequent occurrences. In Python, strings are immutable sequences of characters. When we need to replace specific occurrences, we can use built-in functions like slicing() and replace() or implement custom logic using loops. Problem Statement Given an input string and a replacement character k, replace all occurrences of the first character except the very first occurrence. Example For the string 'blueforblueforblue' with replacement character '*' ? ...
Read MorePython Program to Find Numbers in Range and not in Set
In Python, we can find numbers that exist within a specific range but are not present in a given set using several approaches: the not operator, set subtraction, or the Counter function. A Python set is a collection of unordered, unique elements. Sets are mutable, meaning you can add or remove elements after creation, but the elements themselves must be immutable and distinct. Problem Example Given an input set and a range, find all numbers in the range that don't exist in the set ? Input input_set = {3, 10, 2, 11, 15, 4, ...
Read MorePython Program to Extract Keys with specific Value Type
Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Each key-value combination corresponds to a key and its corresponding value. In this article, we will learn how to extract keys with specific value type in Python using three different approaches. Methods Used The following are the various methods to accomplish this task − Using for loop and isinstance() method Using list comprehension and isinstance() method Using keys() & type() methods Problem Example Let's consider ...
Read MorePython Program to Expand Character Frequency String
A character frequency string contains characters followed by their frequency count. For example, 'p5y3t6' means 'p' appears 5 times, 'y' appears 3 times, and 't' appears 6 times. Expanding this string produces 'pppppyyytttttt'. In this article, we will learn how to expand character frequency strings using different Python approaches. Problem Statement Given an input string where characters alternate with their frequencies, expand each character according to its frequency count ? Example inputString = 'p5y3t6h2o1n4' print("Input:", inputString) print("Expected Output: pppppyyytttttthhonnnn") Input: p5y3t6h2o1n4 Expected Output: pppppyyytttttthhonnnn Method 1: Using zip() and ...
Read MorePython Program to Concatenate all keys which have similar values
Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Each key-value combination corresponds to a key and its corresponding value. In this article, we will learn how to concatenate all keys which have similar values in Python ? Methods Used The following are the various methods to accomplish this task: Using defaultdict() and join() functions Using dictionary comprehension, groupby() and join() functions Example Assume we have taken an input dictionary. We will now concatenate ...
Read MorePython Program to Add K between case shifts
In Python, we can add a symbol between case shifts (transitions from uppercase to lowercase or vice versa) using built-in string methods like isupper(), islower(), and join(). A case shift occurs when consecutive characters change from uppercase to lowercase or lowercase to uppercase. Understanding Case Shifts Let's see what case shifts look like with an example ? # Example of case shifts in a string text = "tUtoRialsPoInt" print("Original string:", text) print("Case shifts occur between:") print("t -> U (lowercase to uppercase)") print("U -> t (uppercase to lowercase)") print("o -> R (lowercase to uppercase)") ...
Read MorePrint all repeating digits present in a given number in sorted order
Finding repeating digits in a number is a common programming task. Python provides several built-in functions like count(), Counter(), and operator.countOf() that can efficiently identify and sort duplicate digits. Problem Statement Given a number, we need to find all digits that appear more than once and display them in sorted order. Input inputNum = 5322789124199 Expected Output 1 2 9 In the input number 5322789124199, digits 1, 2, and 9 appear multiple times, so they are displayed in ascending order. Method 1: Using count() Function The count() method returns ...
Read MoreHow to Convert Dictionary to Concatenated String using Python?
A dictionary in Python is a built-in data structure that allows you to store and retrieve values using unique keys. Converting a dictionary to a concatenated string means combining all keys and values into a single string without separators. For example ? Input = {'one': 1, 'two': 2, 'three': 3} Output = one1two2three3 Let's explore different methods to achieve this conversion. Using a Loop and F-string This method iterates through the dictionary's key-value pairs and concatenates them using an f-string ? dictionary = {'one': 1, 'two': 2, 'three': 3} concatenated_string = ...
Read MoreConvert Image to String and vice-versa in Python
Converting images to string format and back is a common requirement in Python applications. This process involves encoding image binary data into text format for storage, transmission, or processing, then decoding it back to reconstruct the original image. Converting Image to String − This involves transcribing binary image data into text format using encoding schemes like Base64. This conversion is useful for transmitting images through APIs, storing in databases, or sending over text-based protocols. Converting String to Image − This reverses the process by decoding the encoded string back into binary data to reconstruct the original image file. ...
Read MoreHow to Create Custom Turtle shapes in Python?
Python's Turtle library is used for generating 2D graphics and animations. It has a very simple interface with help of which we can create shapes and patterns on the screen. It comes with some built-in shapes like squares, circles, triangles etc. However, we can even create our own shapes with the help of Turtle. In this article, we are going to see how to create custom turtle shapes in python. Before going forward with the creating custom shapes we need to install Turtle on the system and this can be done by simply using the following command − ...
Read More