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 Convert dictionary values to Strings
A dictionary in Python is an unordered collection of key-value pairs. It is a data structure that allows you to store and retrieve values based on a unique key associated with each value. Keys in a dictionary must be immutable (strings, numbers, or tuples), while values can be of any data type and can be mutable. When we want to convert dictionary values to strings, we need to iterate over the dictionary and convert each value to a string using the str() function. Input Output Scenarios See the following input-output scenarios to understand the concept of converting ...
Read MorePython Program to convert Dictionary to List by Repeating keys corresponding value times
In Python, dictionaries are key-value pairs where each key is associated with a corresponding value. When we want to convert a dictionary to a list by repeating keys, we need to iterate over each key-value pair and repeat the key based on its corresponding value. Input Output Scenarios See the following input-output scenarios to understand the concept of converting a dictionary to a list by repeating keys corresponding to the number present in the values ? Input dictionary: {'a': 3, 'b': 2, 'c': 1} Output list: ['a', 'a', 'a', 'b', 'b', 'c'] In the ...
Read MorePython program to convert Dict of list to CSV
A dictionary of lists is a common data structure where each key maps to a list of values. Converting this structure to CSV format is useful for data analysis and sharing tabular data. Here's an example of a dictionary of lists ? data = { 'numbers': [1, 2, 3, 4, 5, 6], 'states': ['UP', 'Tamil Nadu', 'Telangana', 'Gujarat', 'UP', 'Tamil Nadu'], 'cities': ['Agra', 'Chennai', 'Hyderabad', 'Surat', 'Lucknow', 'Coimbatore'] } print(data) {'numbers': [1, 2, 3, 4, 5, 6], 'states': ['UP', 'Tamil Nadu', 'Telangana', ...
Read MoreFinding the Maximum and Minimum in a Python set
Python sets store unique elements in an unordered collection. To find the maximum and minimum values in a set, Python provides several approaches using built-in functions like max(), min(), and sorted(). Using Built-in max() and min() Functions The most direct approach is to apply max() and min() functions directly to the set ? # Define a set with integer values numbers = {5, 2, 8, 1, 9, 18} # Find maximum and minimum values directly maximum = max(numbers) minimum = min(numbers) print("Maximum:", maximum) print("Minimum:", minimum) Maximum: 18 Minimum: 1 ...
Read MorePython program to find volume, surface area and space diagonal of a cuboid
In this article, we will discuss how to compute the volume, surface area, and space diagonal of a cuboid. A cuboid is a 3D geometric shape that resembles a rectangular box, also called a rectangular prism. It has six rectangular faces with twelve edges, where length, breadth, and height are different (unlike a cube where all sides are equal). Understanding Cuboid Formulas Before implementing the code, let's understand the key formulas ? Volume: length × breadth × height Surface Area: 2 × (l×b + b×h + h×l) Space Diagonal: √(l² + b² + h²) ...
Read MorePython Program to get all Possible Slices of a String for K Number of Slices
Getting all possible slices of a string for K number of slices means dividing a string into exactly K parts in all possible ways. Python provides multiple approaches to solve this problem: iteration and using itertools.combinations. Method 1: Using Iterative Approach This method builds slices iteratively by extending existing slices from previous iterations ? def get_all_slices_iteration(string, k): slices = [[]] for i in range(k): new_slices = [] ...
Read MoreHow to make Density Plot in Python with Altair?
Altair is a statistical visualization library in Python based on Vega-Lite grammar. Density plots are useful for visualizing data distribution, comparing groups, and detecting outliers. This article demonstrates how to create density plots using Altair with a practical example. What is a Density Plot? A density plot shows the distribution of a continuous variable by estimating the probability density function. It's similar to a histogram but uses a smooth curve instead of bars. Required Libraries First, let's import the necessary libraries ? import altair as alt import pandas as pd Loading Sample ...
Read MorePython program to find XOR of array elements which are divisible by given number
In this article, we will discuss how to compute the XOR of array elements that are divisible by a given number. The XOR (exclusive OR) is a binary operation that compares the bits of two operands. If the bits are different then it returns 1, whereas it returns 0 if the bits are the same. Understanding XOR Operation Let's understand XOR with a simple example using array [1, 2, 3, 4, 5] ? Initialize xor_value to 0. Begin iterating over each element: First element num = 1, perform xor_value ^ num. Since xor_value = 0, ...
Read MorePython Program to find Jumbo GCD Subarray
The Jumbo GCD Subarray problem involves finding the Greatest Common Divisor (GCD) of a subarray with maximum possible value from a given array. The GCD is the largest positive integer that divides all numbers in a set without remainder. We can solve this using two approaches: brute force and optimized using prefix/suffix arrays. Understanding GCD Before solving the problem, let's implement a helper function to calculate GCD using the Euclidean algorithm ? def gcd(a, b): while b: a, b = b, a % b ...
Read MorePython - Rear stray character String split
When working with strings in Python, you may encounter situations where delimiter characters appear in unexpected places, creating "stray characters" that interfere with standard string splitting operations. This article explores three effective approaches to handle string splitting when delimiters appear after certain words or in non-standard positions. What are Stray Characters in String Splitting? Stray characters are delimiters (like periods, commas, or spaces) that appear in positions where they disrupt normal string splitting patterns. For example, a period that appears immediately after a word without a following space can cause split operations to produce unexpected results. Why ...
Read More