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
211 articles
Difference 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 MoreJavaScript program to retrieve clients IP address
Internet Protocol address, in short, IP address, is a unique address represented by a string of numbers that identifies a device on the internet or a local network. In JavaScript, we can retrieve a client's IP addresses using 3rd party API services such as ipify or ipapi. We can then further use this information to track user locations, personalize content based on the location, or implement security measures. Understanding Client-Side IP Detection JavaScript running in the browser cannot directly access the client's IP address due to security restrictions. However, we can use external APIs that return the public ...
Read MoreJavaScript function to take a number n and generate an array with first n prime numbers
We are required to write a JavaScript function that takes in a number n and returns an array that contains first n prime numbers. We know that prime numbers are those numbers that are only divisible by 1 and themselves like 2, 3, 19, 37, 73 etc. Let's understand the problem with an example − Input: n = 6; Output: prime_numbers = [ 2, 3, 5, 7, 11, 13 ] Using Iteration We will first write a function that checks whether a given number is prime or not and then run a loop ...
Read More