Found 27104 Articles for Server Side Programming

Python Program to convert Dictionary to List by Repeating keys corresponding value times

Gireesha Devara
Updated on 29-Aug-2023 14:10:32

71 Views

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 input dictionary the key 'a' has ... Read More

Python program to convert Dict of list to CSV

Gireesha Devara
Updated on 29-Aug-2023 14:07:37

754 Views

In a dictionary, keys must be unique and immutable, while values can be of any type and can have a list of values. In the case of a dictionary of lists, each key points to a list that can contain multiple elements.  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']}) In the above dictionary, each key is mapped to a list of values. For instance, the 'states' key maps to the list ['UP', 'Tamil Nadu', 'Telangana', ... Read More

Finding the Maximum and Minimum in a Python set

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:45:55

4K+ Views

In this article, the user will see how to calculate the maximum and minimum in a set using Python language. The main feature of the python set is that it contains no duplicates elements, store the elements in unordered form and is also difficult to alter the elements presented in the set. In this article, three different methods are illustrated that is Converting the set to a list, using built-in functions, and using the sorted() function. The ‘sorted()’ function retrieves a set’s element in a sorted way. Approach 1: Finding the maximum and minimum in a Python set ... Read More

Python program to find volume, surface area and space diagonal of a cuboid

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:44:16

2K+ Views

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. It is also called a rectangular prism. A cuboid has six rectangular faces with twelve edges. The length, breadth, and height of a cuboid are different, but in the case of a cube, all sides are equal. Two examples are illustrated in this article. The first example uses the concept of a user-defined function and the second example uses the parameterized constructor of a defined class to calculate the ... Read More

Python Program to get all Possible Slices of a String for K Number of Slices

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:34:08

73 Views

In this article, the user will understand how to get all possible slices of a string for K number of slices in a Python program. Two different examples are depicted in this article. We will employ an iteration approach to accomplish the desired result. In the second example, we will utilize the itertools.combinations approach to obtain the sliced string. Let's take an example to demonstrate the computation. The following examples are provided for understanding purposes, and we will go through the computation process one by one. Example 1: Finding all possible slices of a string for K number of slices ... Read More

How to make Density Plot in Python with Altair?

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:25:02

182 Views

Altair is a kind of statistical visualization library in Python. This library is based on vega and vega-lite javascript libraries. Moreover, we can visualize the data distribution in the form of a density plot in Python. These plots are useful whether we need to compare the variable distribution across the different groups or we need to visualize the distribution shape. The useful applications of density plots such as visualizing data shape, outlier detection, comparing distribution and model selection. The density plot is demonstrated in this article with the help of Python code. For better understanding, we are considering an example ... Read More

Python Program to Generate One-Time Password (OTP)

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:21:42

2K+ Views

In this article, we will discuss how to generate a random one-time password (OTP). We will be using two modules in Python, namely the random and string modules, to accomplish this task. The random module provides relevant functions for generating random numbers, while the string module consists of numerous appropriate string constants. This application can be used for secure authentication or temporary access codes, catering to various aspects and requirements. We will present a few examples to illustrate the different approaches in which these programs can be applied. Let's take an example to demonstrate the computation. The following examples are ... Read More

Python program to find XOR of array elements which are divisible by given number

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:16:51

116 Views

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 will return 1 whereas it returns 0 if the bits are the same. In this approach, we will use the property of XOR and apply this to this problem. The solution to this problem is shown with a relevant example. Let’s take an example to demonstrate the computation. Consider a simple example for understanding purposes, the array ... Read More

Python Program to find Jumbo GCD Subarray

Dr Ruqaiya Khanam
Updated on 28-Aug-2023 14:12:05

56 Views

Jumbo GCD can be referred to find the Greatest Common Divisor (GCD) of a subarray with the maximum length of an array. The GCD is a set of positive integer numbers that divides all the numbers without having a remainder. We can find out the jumbo GCD subarray using two different approaches such as Brute force and Optimized approach using prefix sums. The solution of the jumbo GCD subarray is demonstrated in this article with relevant examples. The Brute force approach can be used to check all possible subarrays of the considering array and to calculate the GCD of an ... Read More

Python - Rear stray character String split

Pranavnath
Updated on 29-Aug-2023 19:55:47

65 Views

Python may be a popular programming dialect known for its effortlessness and coherence. When working with content handling, one common assignment is part of a string based on a particular delimiter. In any case, a challenge emerges when the delimiter shows up after a few words, creating stray characters. In this article, we will explore three distinctive approaches to part a string with stray characters in Python. We will utilize standard expressions, string control with a brief delimiter, and iterative part methods to attain the required result. These approaches give arrangements to handle stray characters and guarantee precise string parts ... Read More

Advertisements