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 on Trending Technologies
Technical articles with clear explanations and examples
Find the tuples containing the given element from a list of tuples in Python
A list can have tuples as its elements. In this article we will learn how to identify those tuples which contain a specific search element from a list of tuples using different methods. Using List Comprehension with Condition We can use list comprehension with a conditional statement to filter tuples that contain the target element ? listA = [('Mon', 3), ('Tue', 1), ('Mon', 2), ('Wed', 3)] test_elem = 'Mon' # Given list print("Given list:") print(listA) print("Check value:") print(test_elem) # Using list comprehension with condition res = [item for item in listA if item[0] == ...
Read MoreHow to set the content as a counter?
CSS counters allow you to automatically number elements on a web page without JavaScript. They work by creating variables that can be incremented and displayed as content using pseudo-elements like ::before and ::after. Syntax /* Reset/create counter */ parent-element { counter-reset: counter-name; } /* Increment and display counter */ element::before { counter-increment: counter-name; content: counter(counter-name); } CSS Counter Properties counter-reset − Creates or resets a counter to zero (or specified value) counter-increment ...
Read MoreFind the Number Occurring Odd Number of Times using Lambda expression and reduce function in Python
In this article, we need to find a number from a list that occurs an odd number of times. We'll use Python's lambda function with the reduce() function to solve this problem efficiently. The key insight is using the XOR (^) operation, which has a special property: when you XOR a number with itself, the result is 0. This means numbers appearing an even number of times will cancel out, leaving only the number that appears an odd number of times. How XOR Works for This Problem Let's understand the XOR logic with a simple example: ...
Read MoreHow to set position of an image in CSS?
In general, the default position of an image is left aligned on the web page. But you can change the position of an image according to your needs and set the position of an image manually on the web page where you have to show that particular image. Let us now discuss about the ways of positioning an image on the webpage using CSS. There are two methods or approaches in general to position an image on the web page using CSS that are listed below − Using the float property of CSS ...
Read MoreFind the list elements starting with specific letter in Python
In this article, we will explore different methods to find all elements from a list that start with a specific letter. Python provides several approaches to achieve this efficiently. Using Index and lower() This method uses the lower() function to make the comparison case-insensitive. We access the first character of each element using index [0] and compare it with the test letter ? days = ['Mon', 'Tue', 'Wed', 'Thu'] test_letter = 'T' print("Given list:") print(days) # Using lower() and index to find elements starting with specific letter result = [item for item in days ...
Read MoreFind most frequent element in a list in Python
In this article, we will see how to find the element which is most common in a given list. In other words, the element with the highest frequency. Python provides several approaches to solve this problem efficiently. Using max() and count() We apply the set() function to get unique elements of the list, then use count() to find the frequency of each element. Finally, we apply max() with a key function to get the element with the highest frequency. Example # Given list numbers = [45, 20, 11, 50, 17, 45, 50, 13, 45] print("Given ...
Read MoreHow to set padding inside an element using CSS?
Padding in CSS creates space between an element's content and its border. This inner spacing helps improve readability and visual appeal by preventing content from touching the element's edges directly. Syntax /* Shorthand property */ padding: value; padding: top-bottom left-right; padding: top left-right bottom; padding: top right bottom left; /* Individual properties */ padding-top: value; padding-right: value; padding-bottom: value; padding-left: value; Possible Values Value TypeDescriptionExample LengthFixed units like px, em, rem10px, 1.5em PercentageRelative to parent element's width5%, 10% autoBrowser calculates paddingauto Method 1: Using Shorthand Padding Property The shorthand ...
Read MoreFind maximum value in each sublist in Python
We are given a list of lists (nested lists). Our task is to find the maximum value in each sublist and return them as a new list. Python provides several approaches to accomplish this efficiently. Using List Comprehension with max() The most Pythonic approach uses list comprehension combined with the max() function to iterate through each sublist ? data = [[10, 13, 454, 66, 44], [10, 8, 7, 23], [5, 15, 25]] # Given list print("The given list:") print(data) # Use max with list comprehension result = [max(sublist) for sublist in data] print("Maximum ...
Read MoreHow to set padding around an element using CSS?
The CSS padding property is used to create space between an element's content and its border. This inner spacing appears inside the element, making the content appear further from the edges. Syntax /* Individual properties */ padding-top: value; padding-right: value; padding-bottom: value; padding-left: value; /* Shorthand property */ padding: value; /* all sides */ padding: vertical horizontal; /* top/bottom left/right */ padding: top horizontal bottom; /* top left/right bottom ...
Read MoreCount tuples occurrence in list of tuples in Python
A list is made up of tuples as its elements. In this article we will count the number of unique tuples present in the list and their occurrences using different approaches. Using defaultdict We treat the given list as a defaultdict data container and count the elements in it using iteration. The defaultdict automatically initializes missing keys with a default value. Example import collections tuple_list = [('Mon', 'Wed'), ('Mon', ), ('Tue', ), ('Mon', 'Wed')] # Given list print("Given list:", tuple_list) res = collections.defaultdict(int) for elem in tuple_list: res[elem] ...
Read More