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 by Disha Verma
45 articles
Adding list elements to tuples list in Python
Our task is to add list items to a tuple list (i.e, a list of tuples) in Python. Tuples store sequences of data enclosed in parentheses, as shown below: Tuples = (11, 22, 33) And the list of tuples is represented as follows: List of tuples = [(11, 22, 33), (44, 55, 66), (77, 88, 99)] Scenario Suppose we have a list of tuples, "a", and another list of items, "b". We have to add all items of the "b" to each item of the "a" as follows ? ...
Read MoreAdding Custom Column to Tuple list in Python
In this article, we will learn how to add a custom column to a list of tuples in Python. Tuples store sequences of data enclosed in parentheses, and when combined into lists, they can represent tabular data structures. Understanding Tuple Lists A single tuple looks like this: (11, 22, 33) A list of tuples represents tabular data: [(11, 22, 33), (44, 55, 66), (77, 88, 99)] Each tuple represents a row, and each position within the tuple represents a column. For example, a student database might look like: ...
Read MoreAdding Custom Values Key in a List of Dictionaries in Python
In this article, we will learn how to add a custom key with corresponding values to a list of dictionaries in Python. This is a common task when working with structured data. Dictionaries in Python are collections of unordered items stored in the form of key-value pairs inside curly braces ? dictionary = {"key": "value", "name": "John"} print(dictionary) {'key': 'value', 'name': 'John'} Suppose we have a list of dictionaries called dict_list and a key new_key, with its values provided in a separate list value_list. The goal is to add new_key to each ...
Read MoreAdding K to each element in a Python list of integers
In this article, we will learn how to add a constant K value to each element in a Python list of integers. A list is a data type in Python that stores a sequence of items separated by commas ? items = [item1, item2, item3...] Suppose we have a list of integers and a constant value "k." We need to add this "k" to each item in the list. For example ? # Input numbers = [5, 10, 15, 20] k = 5 # Output: On adding 5 to each element ...
Read MoreHow to create a Python dictionary from an object\'s fields?
In Python, objects are instances of classes containing attributes and methods, while dictionaries are collections of key-value pairs. Converting an object's fields to a dictionary is useful for serialization, debugging, or data processing. Python provides two main approaches for this conversion. Using __dict__ Attribute Every Python object has a __dict__ attribute that stores the object's attributes and their values as a dictionary. This attribute directly exposes the internal namespace of the object ? Example class Company: def __init__(self, company_name, location): self.company_name = company_name ...
Read MoreWhat does \'is\' operator do in Python?
The "is" operator in Python is an identity operator that checks whether two variables refer to the same object in memory. It returns True if both variables point to the same object, and False otherwise. Each object in Python's memory has a unique identification number assigned by the interpreter. The is operator compares these memory addresses using the id() function internally, making it different from the == operator which compares values. Syntax variable1 is variable2 The is operator returns True if both variables reference the same object in memory, False otherwise. Example with ...
Read MoreWhat does these operators mean (** , ^ , %, //) ?
In Python, there are various types of operators used to perform specific functions, such as (**), (^), (%), and (//). The (**) operator represents exponentiation, (^) represents bitwise XOR, (%) represents the modulus operation, and (//) represents floor division. In this article, we will understand the workings of these operators. Exponentiation Operator (**) The exponentiation operator (**) is used to raise a number to a power. This operator works the same as the Python pow() method. In exponentiation, you need two numbers: the first is the base (the number you want to raise), and the second is the ...
Read MoreWhat is the difference between = and == operators in Python?
The symbols "=" and "==" look similar but have different meanings and usability in Python. The "=" symbol is the assignment operator, and the "==" symbol represents a comparison operator. In this article, we will understand the difference between these two and how to use them. The "=" Operator The "=" operator in Python is the assignment operator. It is used to assign a value to a variable. You put the variable on the left side and the value or expression on the right side. The value on the right is stored in the variable on the left. ...
Read MoreWhat is different in OR and AND operators in Python?
The OR and AND operators are the most commonly used logical operators in Python. These operators are used to perform decision-making operations by combining multiple conditions. In this article, we will understand what OR and AND operators are in Python and how they differ, along with examples for better understanding. AND Operator in Python The logical AND operator in Python needs two operands. It returns True if both operands are true, and it returns False if either of the operands is false. This operator is mostly used in situations where you want to make sure that two conditions ...
Read MoreWhat is modulo % operator in Python?
The modulo operator is denoted by the "%" symbol in Python. It returns the remainder of the division between two numeric operands, making it useful for solving problems ranging from simple arithmetic to complex mathematical operations. Syntax The modulo operator works by returning the remainder after dividing two numbers ? result = a % b Where a and b are the operands, % represents the modulo operator, and result stores the remainder of dividing a by b. Modulo Operator with Integers Using the modulo operator with integers is the most common use ...
Read More