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 Harshit Sachan
Page 2 of 3
Python Program to add element to first and last position of linked list
In Python, a linked list is a linear data structure that consists of a chain of nodes, where each node contains a value and a reference to the next node in the chain. In this article, we will be discussing how to add an element to the first and last position of a linked list in Python. Linked List in Python A linked list is a referential data structure that holds a group of elements. It is similar to an array but while data is stored in contiguous memory locations in an array, in a linked list ...
Read MorePython Program to remove duplicate elements from a dictionary
In this article, we will discuss how to remove duplicate elements from a dictionary in Python. A dictionary stores key-value pairs where keys must be unique, but values can be duplicated. Sometimes we need to clean up data by keeping only unique values. We can declare a dictionary in the following way − sample_dict = {"brand": "Ford", "model": "Mustang", "year": 1964} print(sample_dict) {'brand': 'Ford', 'model': 'Mustang', 'year': 1964} A dictionary can contain duplicate values for different keys, but we might want to have only unique values. Let's explore two methods to remove ...
Read MorePython program to print the keys and values of the tuple
In Python, tuples are a useful data type for storing a collection of items. Sometimes, it may be necessary to print the keys and values of a tuple in order to understand or debug your code. In this article, we will discuss how to print the keys and values of a tuple in Python. We will go over the syntax for accessing these elements and provide examples of how to do so. First, let's understand what tuples are and what we mean by keys and values in the context of tuples. What is a Python Tuple? ...
Read MorePython program to get first and last elements from a tuple
Tuples are an important data type in Python that store multiple elements in a fixed order. In this article, we'll learn different methods to access the first and last elements from a tuple efficiently. What is a Tuple in Python? A tuple is an ordered collection of items that is immutable (unchangeable). Tuples are defined using round brackets and can store elements of different data types. Example fruits = ("apple", "banana", "cherry") print(fruits) print(type(fruits)) ('apple', 'banana', 'cherry') Method 1: Using Index Notation The most straightforward way to access ...
Read MorePython Program to compare elements in two dictionaries
Dictionaries are a powerful data type in Python that allow you to store data as key-value pairs. In this article, we will discuss how to compare elements in two dictionaries using three different approaches: equality operator, loops, and list comprehension. Understanding Dictionaries In Python, a dictionary is created by placing key-value pairs within curly brackets { }, separated by commas. Values can be of any data type and can be duplicated, whereas keys must be unique and immutable. # Creating dictionaries dict1 = {"brand": "Ford", "model": "Mustang", "year": 1964} dict2 = {"brand": "Toyota", "model": "Camry", "year": ...
Read MorePython program to print even numbers in a list
Python lists are fundamental data structures that store collections of items. Finding even numbers in a list is a common programming task with multiple efficient approaches. A number is even if it divides by 2 with no remainder. We will explore several methods to print even numbers from a list, each with different advantages ? Using Modulo Operator The modulo operator (%) returns the remainder when dividing two numbers. For even numbers, x % 2 == 0 will be true. Example def print_evens(numbers): for num in numbers: ...
Read MorePython program to print even length words in a string
In Python, you can find and print all words in a string that have even length (divisible by 2). This is useful for text processing tasks where you need to filter words based on their character count. For example, in the string "A big cube was found inside the box", the words "cube" (length 4) and "inside" (length 6) have even lengths. Basic Approach The simplest method involves splitting the string into words and checking each word's length ? def print_even_length_words(text): # Split the string into individual words ...
Read MoreHow to transform background image using CSS3
The CSS transform property allows you to apply 2D and 3D transformations to elements, including background images. You can rotate, scale, translate, and skew elements to create visual effects without affecting the document flow. Syntax selector { transform: none | transform-function | initial | inherit; } Transform Functions FunctionDescription rotate(angle)Rotates element by specified angle scale(x, y)Scales element along X and Y axes translate(x, y)Moves element along X and Y axes skew(x-angle, y-angle)Skews element along X and Y axes Example: Rotating Background Image The following example demonstrates ...
Read MoreHow to create an accordion hover effect with box-shadows in CSS
An accordion hover effect with box-shadows in CSS creates an interactive element that expands content when hovered over, while adding visual depth through shadows. This effect combines CSS transitions, hover states, and the box-shadow property to create smooth, engaging user interactions. Syntax selector { box-shadow: x-offset y-offset blur-radius spread-radius color; } selector:hover { box-shadow: x-offset y-offset blur-radius spread-radius color; } Box-Shadow Property Values PropertyDescription x-offsetHorizontal shadow position (positive = right, negative = left) y-offsetVertical shadow position (positive = down, negative = up) blur-radiusOptional. Controls ...
Read MoreHow to create a Non-Rectangular Header using HTML & CSS
A non-rectangular header adds visual appeal to web pages by breaking away from traditional rectangular layouts. Using CSS's clip-path property, we can create custom shapes for headers that make our designs stand out. Syntax header { clip-path: polygon(coordinates); } Basic Approach To create a non-rectangular header, we use the following steps − Create a element with content Apply the clip-path CSS property with polygon coordinates Position content appropriately within the clipped area Example 1: Wavy Bottom Header Here's how to create a header with a ...
Read More