Server Side Programming Articles

Page 49 of 2109

Python Program to Set from dictionary values

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 2K+ Views

In Python, a dictionary is an implementation of a data structure known as an associative array. A dictionary is made up of key-value pairs, where each key maps to its corresponding value. In this article, we will learn how to extract unique values from a dictionary and convert them into a set, which automatically removes duplicates. Example Overview Let's start with an example to understand what we want to achieve ? # Input dictionary with duplicate values input_dict = {'hello': 5, 'tutorialspoint': 10, 'users': 15, 'python': 5} print("Input dictionary:", input_dict) print("Dictionary values:", list(input_dict.values())) # ...

Read More

Python Program to Rotate dictionary by K

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 388 Views

Python dictionaries are ordered collections of key-value pairs. Sometimes you need to rotate a dictionary by K positions, which means shifting all key-value pairs by K positions in their order. This article demonstrates how to rotate a dictionary by K positions using two different approaches. Understanding Dictionary Rotation Dictionary rotation shifts all key-value pairs by K positions. For example, rotating {2: 5, 4: 6, 1: 3} by 1 position gives {1: 3, 2: 5, 4: 6}. Example Input and Output # Input dictionary inputDict = {2: 5, 4: 6, 1: 3, 9: 4, 5: 1} ...

Read More

Python Program to Retain first N Elements of a String and Replace the Remaining by K

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 263 Views

In this article, we will learn how to retain the first N characters of a string and replace the remaining characters with a specified character K. Python provides several built-in functions like len(), slicing, replace(), and ljust() to accomplish this task efficiently. Problem Overview Given an input string, we need to keep the first N characters unchanged and replace all remaining characters with a replacement character K. Example Let's understand this with a simple example ? # Input input_string = 'tutorialspoint' n = 9 k = "#" # Expected output: 'tutorials#####' print(f"Original: {input_string}") ...

Read More

Python Program to Replace occurrences by K except first character

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 802 Views

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 More

Python Program to Find Numbers in Range and not in Set

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 525 Views

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 More

Python Program to Extract Keys with specific Value Type

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 251 Views

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 More

Python Program to Expand Character Frequency String

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 509 Views

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 More

Python Program to Concatenate all keys which have similar values

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 187 Views

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 More

Python Program to Add K between case shifts

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 162 Views

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 More

Print all repeating digits present in a given number in sorted order

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 872 Views

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 More
Showing 481–490 of 21,090 articles
« Prev 1 47 48 49 50 51 2109 Next »
Advertisements