Found 10784 Articles for Python

Python program to convert int to exponential

Gireesha Devara
Updated on 29-Aug-2023 14:17:26

1K+ Views

Exponential notation also known as scientific notation, is a way to express numbers that are very large or very small using a combination of a coefficient and an exponent. It is commonly used in scientific and mathematical calculations. In exponential notation, a number is expressed as the product of a coefficient and a power of 10. The coefficient is typically a decimal number between 1 and 10, and the power of 10 indicates the scale of the number. For example − The number 1, 000, 000 can be expressed as 1 x 10^6 or 1e+6 in exponential notation. The ... Read More

Python program to convert float to exponential

Gireesha Devara
Updated on 29-Aug-2023 14:18:23

2K+ Views

Float to exponential conversion involves transforming a decimal number, represented as a float, into exponential notation, also known as scientific notation. Exponential notation is commonly used for expressing very large or very small numbers in a concise manner, particularly in scientific and mathematical calculations. On the other hand, a float is a data type used to store real numbers, including both whole and fractional numbers. In Python, floats are commonly used to represent floating-point numbers. The process of converting a float to exponential can be achieved using various approaches in Python, such as using the format() function, f-string formatting, or ... Read More

Python Program To Convert dictionary values to Strings

Gireesha Devara
Updated on 29-Aug-2023 14:19:41

279 Views

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 are used to uniquely identify values, and they must be immutable, such as strings, numbers, or tuples. On the other hand, the associated values in a dictionary can be of any data type and can be mutable. When we want to convert a dictionary values to strings, we need to iterate over the dictionary using a loop and convert each value to a ... Read More

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

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

72 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

818 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

74 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

Advertisements