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 Shriansh Kumar
Page 2 of 22
Appending to list in Python Dictionary
Sometimes, we may need to store a list as the value of a dictionary key and later update or add more elements to that list. Python provides several ways for appending elements to a list in a Python dictionary. In this article, we'll explore the append() method, += operator, and update() method for this purpose. Understanding Lists and Dictionaries Before diving into the methods, let's understand the basic data structures we're working with. List A list is an ordered and mutable collection of elements. We create lists by placing elements in square brackets separated by commas ...
Read MoreAll Combinations For A List Of Objects
Generating all combinations for a list of objects is a common operation in Python. The itertools module provides efficient built-in methods like combinations() and product() to generate different types of combinations from list objects. Using itertools.combinations() The combinations() method generates all possible combinations of a specified length without repetition. It's perfect for mathematical combinations where order doesn't matter and elements can't repeat. Syntax itertools.combinations(iterable, length) Where iterable is the input sequence and length is the size of each combination. Example 1: Basic Combinations Generate all combinations of different lengths from a ...
Read MoreDifference between List and Tuples in Python
Lists and tuples are built-in data types in Python programming language. They serve as containers to hold multiple values of the same type as well as different data types. Understanding the differences between lists and tuples is crucial for choosing the right data structure for your Python programs. This article explores their key characteristics and differences. List in Python A list is a mutable container that holds different types of objects. Elements are separated by commas and enclosed within square brackets. Each element has a unique position index starting from 0. Creating and Modifying Lists ...
Read More10 Interesting Python Cool Tricks
With the increase in popularity of the Python programming language, more and more features are becoming available for Python developers. Usage of these features helps us write efficient and cleaner code. In this article, we will explore 10 Python tricks that can make your code more concise and efficient. Reversing a List We can reverse a given list using the reverse() function. It modifies the original list in place and works with both numeric and string datatypes. Example Let's see how to use the reverse() function to reverse a list of strings ? ...
Read MorenHow to print out the first character of each list in Python?
A Python list is a built-in, mutable datatype that stores multiple items or elements, separated by commas, within square brackets [ ]. The index of a list in Python starts from 0 up to length-1. We can retrieve/access elements at a particular index as follows ? list_name[index] The given task is to write a Python program that prints the first character of each element in a list. But, before that, let's see some example scenarios: Scenario 1 For example, if our list contains string values, the output should be the first character of ...
Read MoreJavaScript Program for Left Rotation and Right Rotation of a String
To implement left rotation and right rotation of a string, we can use various approaches. Left rotation means moving characters counter-clockwise by a given number of positions, while right rotation means moving characters clockwise by a given number of positions. In this article we have a string and a value of k by which we will rotate the string. Our task is to write a JavaScript program for left rotation and right rotation of a string. Example Input: String str = "apple"; k = 3 Output: Left Rotation: "leapp" Right Rotation: "pleap" Approaches ...
Read MoreJavaScript in filter an associative array with another array
In this article, we'll explore how to filter an associative array using another array in JavaScript. This is a common task when you need to extract specific objects from a dataset based on matching criteria. What is an Associative Array? An associative array is a data structure that stores key-value pairs. Each key is associated with a specific value and serves as a unique identifier. Unlike regular arrays, associative arrays don't use numeric indexes—keys can be strings or numbers. In JavaScript, objects function as associative arrays since they store key-value pairs where keys can be strings or ...
Read MoreJavaScript: How to check if a number is even without using the modulo operator?
For a given integer number, write a program in JavaScript to check whether a number is odd or even and return the same to the user. It's pretty easy to check whether a number is even by using the modulo operator. But, in this article, we will be checking whether a number is even or not without using the modulo operator. Using the For Loop In this approach, we are going to use the for loop to check whether a number is even or not. The idea is to take a Boolean flag variable as true and toggle ...
Read MoreJavaScript Program to Check if a Given Year is Leap Year
To check if a given year is leap year, we have used two approaches in this article. A leap year has 366 days. In every 4th year, an additional day is added to the month of February to synchronize it with the astronomical year. In this article, we are given with two years to check. Our task is to write a JavaScript program to check if a given year is leap year. Leap Year Rules A year is considered a leap year if it follows these rules: Divisible by 4 AND not divisible ...
Read MoreJavaScript clearTimeout() & clearInterval() Method
In JavaScript, the clearTimeout() and clearInterval() methods are used to clear timers. When we set a timer using setTimeout() or setInterval() methods, the browser allocates memory to track it. Therefore, we use these methods to release that memory and avoid unnecessary function calls. It is best practice to clear timers when they are no longer needed to prevent memory leaks and unwanted executions. JavaScript clearTimeout() Method The clearTimeout() method clears a timeout that was previously set by setTimeout(). It prevents the scheduled function from executing if called before the timeout completes. Syntax clearTimeout(timeoutID) Parameters ...
Read More